diff mbox series

[bpf-next,v2] libbpf: Deprecate bpf_object__unload() API since v0.7

Message ID 20211002161000.3854559-1-hengqi.chen@gmail.com (mailing list archive)
State Accepted
Delegated to: BPF
Headers show
Series [bpf-next,v2] libbpf: Deprecate bpf_object__unload() API since v0.7 | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for bpf-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 4 maintainers not CCed: kafai@fb.com kpsingh@kernel.org songliubraving@fb.com netdev@vger.kernel.org
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 10 this patch: 10
netdev/verify_fixes success Link
netdev/checkpatch warning WARNING: Prefer __alias("bpf_object__unload") over __attribute__((alias("bpf_object__unload"))) WARNING: line length of 100 exceeds 80 columns
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next success VM_Test

Commit Message

Hengqi Chen Oct. 2, 2021, 4:10 p.m. UTC
BPF objects are not re-loadable after unload. User 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 bpf_object__unload() and replace
all bpf_object__unload() to avoid compilation errors.

  [0] Closes: https://github.com/libbpf/libbpf/issues/290

Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
---
 tools/lib/bpf/libbpf.c | 7 +++++--
 tools/lib/bpf/libbpf.h | 1 +
 2 files changed, 6 insertions(+), 2 deletions(-)

--
2.25.1

Comments

Song Liu Oct. 5, 2021, 1:06 a.m. UTC | #1
On Sat, Oct 2, 2021 at 9:31 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
>
> BPF objects are not re-loadable after unload. User 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 bpf_object__unload() and replace
> all bpf_object__unload() to avoid compilation errors.
>
>   [0] Closes: https://github.com/libbpf/libbpf/issues/290
>
> Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>

Acked-by: Song Liu <songliubraving@fb.com>
Andrii Nakryiko Oct. 6, 2021, 5:39 p.m. UTC | #2
On Mon, Oct 4, 2021 at 6:06 PM Song Liu <song@kernel.org> wrote:
>
> On Sat, Oct 2, 2021 at 9:31 AM Hengqi Chen <hengqi.chen@gmail.com> wrote:
> >
> > BPF objects are not re-loadable after unload. User 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 bpf_object__unload() and replace
> > all bpf_object__unload() to avoid compilation errors.
> >
> >   [0] Closes: https://github.com/libbpf/libbpf/issues/290
> >
> > Signed-off-by: Hengqi Chen <hengqi.chen@gmail.com>
>
> Acked-by: Song Liu <songliubraving@fb.com>

Applied to bpf-next, thanks. I've done few changes, though:

1. started deprecation from the current development version (0.6),
there is no point in delaying this as the recommended replacement API
(bpf_object__close()) has been available forever.
2. it didn't make sense to me to have bpf_object_unload as an alias to
bpf_object__unload, I switched it around, bpf_object__unload is an
alias of internal bpf_object_unload. It will also make further
deletion of bpf_object__unload() simpler in the future.

Please let me know if you have any reservations about this.
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index e23f1b6b9402..7de3dcbd61f2 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -6679,6 +6679,9 @@  int bpf_object__unload(struct bpf_object *obj)
 	return 0;
 }

+__attribute__((alias("bpf_object__unload")))
+static int bpf_object_unload(struct bpf_object *obj);
+
 static int bpf_object__sanitize_maps(struct bpf_object *obj)
 {
 	struct bpf_map *m;
@@ -7055,7 +7058,7 @@  int bpf_object__load_xattr(struct bpf_object_load_attr *attr)
 		if (obj->maps[i].pinned && !obj->maps[i].reused)
 			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);
 	return libbpf_err(err);
 }
@@ -7664,7 +7667,7 @@  void bpf_object__close(struct bpf_object *obj)

 	bpf_gen__free(obj->gen_loader);
 	bpf_object__elf_finish(obj);
-	bpf_object__unload(obj);
+	bpf_object_unload(obj);
 	btf__free(obj->btf);
 	btf_ext__free(obj->btf_ext);

diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index e35490c54eb3..ada0388ca1f2 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -150,6 +150,7 @@  struct bpf_object_load_attr {
 /* Load/unload object into/from kernel */
 LIBBPF_API int bpf_object__load(struct bpf_object *obj);
 LIBBPF_API int bpf_object__load_xattr(struct bpf_object_load_attr *attr);
+LIBBPF_DEPRECATED_SINCE(0, 7, "bpf_object__unload() is deprecated, use bpf_object__close() instead")
 LIBBPF_API int bpf_object__unload(struct bpf_object *obj);

 LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj);