Skip to content

Commit 9ff1634

Browse files
christycyleeNobody
authored andcommitted
libbpf: deprecate bpf_object__open() API
Deprecate bpf_object__open() in favor of bpf_object__open_file(). Signed-off-by: Christy Lee <christylee@fb.com>
1 parent 20679c4 commit 9ff1634

File tree

10 files changed

+13
-12
lines changed

10 files changed

+13
-12
lines changed

Documentation/bpf/prog_lsm.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ eBPF programs can be loaded with the :manpage:`bpf(2)` syscall's
102102
103103
struct bpf_object *obj;
104104
105-
obj = bpf_object__open("./my_prog.o");
105+
obj = bpf_object__open_file("./my_prog.o", NULL);
106106
bpf_object__load(obj);
107107
108108
This can be simplified by using a skeleton header generated by ``bpftool``:

tools/bpf/bpftool/Documentation/bpftool-gen.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ DESCRIPTION
4646
individually compiled files that are then linked into
4747
a single resulting BPF object file, which can be used to
4848
generated BPF skeleton (with **gen skeleton** command) or
49-
passed directly into **libbpf** (using **bpf_object__open()**
49+
passed directly into **libbpf** (using **bpf_object__open_file()**
5050
family of APIs).
5151

5252
**bpftool gen skeleton** *FILE*

tools/bpf/bpftool/iter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int do_pin(int argc, char **argv)
4545
}
4646
}
4747

48-
obj = bpf_object__open(objfile);
48+
obj = bpf_object__open_file(objfile, NULL);
4949
err = libbpf_get_error(obj);
5050
if (err) {
5151
p_err("can't open objfile %s", objfile);

tools/build/feature/test-libbpf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
int main(void)
55
{
6-
return bpf_object__open("test") ? 0 : -1;
6+
return bpf_object__open_file("test", NULL) ? 0 : -1;
77
}

tools/lib/bpf/libbpf.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ struct bpf_object_open_opts {
150150
};
151151
#define bpf_object_open_opts__last_field kernel_log_level
152152

153+
LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_object__open_file() instead")
153154
LIBBPF_API struct bpf_object *bpf_object__open(const char *path);
154155

155156
/**
@@ -807,10 +808,10 @@ struct bpf_prog_load_attr {
807808
int prog_flags;
808809
};
809810

810-
LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_object__open() and bpf_object__load() instead")
811+
LIBBPF_DEPRECATED_SINCE(0, 8, "use bpf_object__open_file() and bpf_object__load() instead")
811812
LIBBPF_API int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
812813
struct bpf_object **pobj, int *prog_fd);
813-
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_object__open() and bpf_object__load() instead")
814+
LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_object__open_file() and bpf_object__load() instead")
814815
LIBBPF_API int bpf_prog_load_deprecated(const char *file, enum bpf_prog_type type,
815816
struct bpf_object **pobj, int *prog_fd);
816817

tools/perf/util/bpf-loader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct bpf_object *bpf__prepare_load(const char *filename, bool source)
101101

102102
free(obj_buf);
103103
} else
104-
obj = bpf_object__open(filename);
104+
obj = bpf_object__open_file(filename, NULL);
105105

106106
if (IS_ERR_OR_NULL(obj)) {
107107
pr_debug("bpf: failed to load %s\n", filename);

tools/testing/selftests/bpf/prog_tests/btf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4560,7 +4560,7 @@ static void do_test_file(unsigned int test_num)
45604560
has_btf_ext = btf_ext != NULL;
45614561
btf_ext__free(btf_ext);
45624562

4563-
obj = bpf_object__open(test->file);
4563+
obj = bpf_object__open_file(test->file, NULL);
45644564
err = libbpf_get_error(obj);
45654565
if (CHECK(err, "obj: %d", err))
45664566
return;

tools/testing/selftests/bpf/prog_tests/select_reuseport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static int prepare_bpf_obj(void)
9191
struct bpf_map *map;
9292
int err;
9393

94-
obj = bpf_object__open("test_select_reuseport_kern.o");
94+
obj = bpf_object__open_file("test_select_reuseport_kern.o", NULL);
9595
err = libbpf_get_error(obj);
9696
RET_ERR(err, "open test_select_reuseport_kern.o",
9797
"obj:%p PTR_ERR(obj):%d\n", obj, err);

tools/testing/selftests/bpf/test_maps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ static void test_map_in_map(void)
11561156
__u32 id = 0;
11571157
libbpf_print_fn_t old_print_fn;
11581158

1159-
obj = bpf_object__open(MAPINMAP_PROG);
1159+
obj = bpf_object__open_file(MAPINMAP_PROG, NULL);
11601160

11611161
fd = bpf_map_create(BPF_MAP_TYPE_HASH, NULL, sizeof(int), sizeof(int), 2, NULL);
11621162
if (fd < 0) {
@@ -1227,7 +1227,7 @@ static void test_map_in_map(void)
12271227
bpf_object__close(obj);
12281228

12291229
/* Test that failing bpf_object__create_map() destroys the inner map */
1230-
obj = bpf_object__open(MAPINMAP_INVALID_PROG);
1230+
obj = bpf_object__open_file(MAPINMAP_INVALID_PROG, NULL);
12311231
err = libbpf_get_error(obj);
12321232
if (err) {
12331233
printf("Failed to load %s program: %d %d",

tools/testing/selftests/bpf/test_sockmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1761,7 +1761,7 @@ static int populate_progs(char *bpf_file)
17611761
int i = 0;
17621762
long err;
17631763

1764-
obj = bpf_object__open(bpf_file);
1764+
obj = bpf_object__open_file(bpf_file, NULL);
17651765
err = libbpf_get_error(obj);
17661766
if (err) {
17671767
char err_buf[256];

0 commit comments

Comments
 (0)