diff options
-rw-r--r-- | tools/lib/bpf/libbpf.c | 22 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.h | 1 |
2 files changed, 23 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index c4465b2fddf6..6a8c8beeb291 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -1357,6 +1357,28 @@ int bpf_program__pin(struct bpf_program *prog, const char *path) | |||
1357 | return 0; | 1357 | return 0; |
1358 | } | 1358 | } |
1359 | 1359 | ||
1360 | int bpf_map__pin(struct bpf_map *map, const char *path) | ||
1361 | { | ||
1362 | int err; | ||
1363 | |||
1364 | err = check_path(path); | ||
1365 | if (err) | ||
1366 | return err; | ||
1367 | |||
1368 | if (map == NULL) { | ||
1369 | pr_warning("invalid map pointer\n"); | ||
1370 | return -EINVAL; | ||
1371 | } | ||
1372 | |||
1373 | if (bpf_obj_pin(map->fd, path)) { | ||
1374 | pr_warning("failed to pin map: %s\n", strerror(errno)); | ||
1375 | return -errno; | ||
1376 | } | ||
1377 | |||
1378 | pr_debug("pinned map '%s'\n", path); | ||
1379 | return 0; | ||
1380 | } | ||
1381 | |||
1360 | void bpf_object__close(struct bpf_object *obj) | 1382 | void bpf_object__close(struct bpf_object *obj) |
1361 | { | 1383 | { |
1362 | size_t i; | 1384 | size_t i; |
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 9f8aa63b95f4..2addf9d5b13c 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h | |||
@@ -236,6 +236,7 @@ typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); | |||
236 | int bpf_map__set_priv(struct bpf_map *map, void *priv, | 236 | int bpf_map__set_priv(struct bpf_map *map, void *priv, |
237 | bpf_map_clear_priv_t clear_priv); | 237 | bpf_map_clear_priv_t clear_priv); |
238 | void *bpf_map__priv(struct bpf_map *map); | 238 | void *bpf_map__priv(struct bpf_map *map); |
239 | int bpf_map__pin(struct bpf_map *map, const char *path); | ||
239 | 240 | ||
240 | long libbpf_get_error(const void *ptr); | 241 | long libbpf_get_error(const void *ptr); |
241 | 242 | ||