Commit 4a404a7e authored by Hengqi Chen's avatar Hengqi Chen Committed by Andrii Nakryiko

libbpf: Deprecate bpf_object__unload() API since v0.6

BPF objects are not reloadable after unload. Users are expected to use
bpf_object__close() to unload and free up resources in one operation.
No need to expose bpf_object__unload() as a public API, deprecate it
([0]).  Add bpf_object__unload() as an alias to internal
bpf_object_unload() and replace all bpf_object__unload() uses to avoid
compilation errors.

  [0] Closes: https://github.com/libbpf/libbpf/issues/290Signed-off-by: default avatarHengqi Chen <hengqi.chen@gmail.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20211002161000.3854559-1-hengqi.chen@gmail.com
parent 93303034
...@@ -6672,7 +6672,7 @@ bpf_object__open_buffer(const void *obj_buf, size_t obj_buf_sz, ...@@ -6672,7 +6672,7 @@ bpf_object__open_buffer(const void *obj_buf, size_t obj_buf_sz,
return libbpf_ptr(__bpf_object__open(NULL, obj_buf, obj_buf_sz, &opts)); return libbpf_ptr(__bpf_object__open(NULL, obj_buf, obj_buf_sz, &opts));
} }
int bpf_object__unload(struct bpf_object *obj) static int bpf_object_unload(struct bpf_object *obj)
{ {
size_t i; size_t i;
...@@ -6691,6 +6691,8 @@ int bpf_object__unload(struct bpf_object *obj) ...@@ -6691,6 +6691,8 @@ int bpf_object__unload(struct bpf_object *obj)
return 0; return 0;
} }
int bpf_object__unload(struct bpf_object *obj) __attribute__((alias("bpf_object_unload")));
static int bpf_object__sanitize_maps(struct bpf_object *obj) static int bpf_object__sanitize_maps(struct bpf_object *obj)
{ {
struct bpf_map *m; struct bpf_map *m;
...@@ -7089,7 +7091,7 @@ int bpf_object__load_xattr(struct bpf_object_load_attr *attr) ...@@ -7089,7 +7091,7 @@ int bpf_object__load_xattr(struct bpf_object_load_attr *attr)
if (obj->maps[i].pinned && !obj->maps[i].reused) if (obj->maps[i].pinned && !obj->maps[i].reused)
bpf_map__unpin(&obj->maps[i], NULL); bpf_map__unpin(&obj->maps[i], NULL);
bpf_object__unload(obj); bpf_object_unload(obj);
pr_warn("failed to load object '%s'\n", obj->path); pr_warn("failed to load object '%s'\n", obj->path);
return libbpf_err(err); return libbpf_err(err);
} }
...@@ -7698,7 +7700,7 @@ void bpf_object__close(struct bpf_object *obj) ...@@ -7698,7 +7700,7 @@ void bpf_object__close(struct bpf_object *obj)
bpf_gen__free(obj->gen_loader); bpf_gen__free(obj->gen_loader);
bpf_object__elf_finish(obj); bpf_object__elf_finish(obj);
bpf_object__unload(obj); bpf_object_unload(obj);
btf__free(obj->btf); btf__free(obj->btf);
btf_ext__free(obj->btf_ext); btf_ext__free(obj->btf_ext);
......
...@@ -150,6 +150,7 @@ struct bpf_object_load_attr { ...@@ -150,6 +150,7 @@ struct bpf_object_load_attr {
/* Load/unload object into/from kernel */ /* Load/unload object into/from kernel */
LIBBPF_API int bpf_object__load(struct bpf_object *obj); LIBBPF_API int bpf_object__load(struct bpf_object *obj);
LIBBPF_API int bpf_object__load_xattr(struct bpf_object_load_attr *attr); LIBBPF_API int bpf_object__load_xattr(struct bpf_object_load_attr *attr);
LIBBPF_DEPRECATED_SINCE(0, 6, "bpf_object__unload() is deprecated, use bpf_object__close() instead")
LIBBPF_API int bpf_object__unload(struct bpf_object *obj); LIBBPF_API int bpf_object__unload(struct bpf_object *obj);
LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj); LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment