Skip to content

Commit 068ca52

Browse files
danobianakryiko
authored andcommitted
libbpf: Add bpf_object__unpin()
For bpf_object__pin_programs() there is bpf_object__unpin_programs(). Likewise bpf_object__unpin_maps() for bpf_object__pin_maps(). But no bpf_object__unpin() for bpf_object__pin(). Adding the former adds symmetry to the API. It's also convenient for cleanup in application code. It's an API I would've used if it was available for a repro I was writing earlier. Signed-off-by: Daniel Xu <dxu@dxuuu.xyz> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Reviewed-by: Song Liu <song@kernel.org> Link: https://lore.kernel.org/bpf/b2f9d41da4a350281a0b53a804d11b68327e14e5.1692832478.git.dxu@dxuuu.xyz
1 parent f586a77 commit 068ca52

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8376,6 +8376,21 @@ int bpf_object__pin(struct bpf_object *obj, const char *path)
83768376
return 0;
83778377
}
83788378

8379+
int bpf_object__unpin(struct bpf_object *obj, const char *path)
8380+
{
8381+
int err;
8382+
8383+
err = bpf_object__unpin_programs(obj, path);
8384+
if (err)
8385+
return libbpf_err(err);
8386+
8387+
err = bpf_object__unpin_maps(obj, path);
8388+
if (err)
8389+
return libbpf_err(err);
8390+
8391+
return 0;
8392+
}
8393+
83798394
static void bpf_map__destroy(struct bpf_map *map)
83808395
{
83818396
if (map->inner_map) {

tools/lib/bpf/libbpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ LIBBPF_API int bpf_object__pin_programs(struct bpf_object *obj,
266266
LIBBPF_API int bpf_object__unpin_programs(struct bpf_object *obj,
267267
const char *path);
268268
LIBBPF_API int bpf_object__pin(struct bpf_object *object, const char *path);
269+
LIBBPF_API int bpf_object__unpin(struct bpf_object *object, const char *path);
269270

270271
LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj);
271272
LIBBPF_API unsigned int bpf_object__kversion(const struct bpf_object *obj);

tools/lib/bpf/libbpf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ LIBBPF_1.2.0 {
395395
LIBBPF_1.3.0 {
396396
global:
397397
bpf_obj_pin_opts;
398+
bpf_object__unpin;
398399
bpf_prog_detach_opts;
399400
bpf_program__attach_netfilter;
400401
bpf_program__attach_tcx;

0 commit comments

Comments
 (0)