aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/libbpf.c
diff options
context:
space:
mode:
authorJoe Stringer <joe@ovn.org>2017-01-26 16:19:57 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-01-31 14:20:06 -0500
commitb6989f35e80bf830f8dc97b74128d619faef0273 (patch)
tree2c594241f77c1cbdab20eb1de42a224f72b85adf /tools/lib/bpf/libbpf.c
parentf367540c8c13d65603c431e29a0b87a7db893d6c (diff)
tools lib bpf: Add bpf_map__pin()
Add a new API to pin a BPF map to the filesystem. The user can specify the path full path within a BPF filesystem to pin the map. Signed-off-by: Joe Stringer <joe@ovn.org> Cc: Alexei Starovoitov <ast@fb.com> Cc: Daniel Borkmann <daniel@iogearbox.net> Cc: Wang Nan <wangnan0@huawei.com> Cc: netdev@vger.kernel.org Link: http://lkml.kernel.org/r/20170126212001.14103-3-joe@ovn.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r--tools/lib/bpf/libbpf.c22
1 files changed, 22 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
1360int 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
1360void bpf_object__close(struct bpf_object *obj) 1382void bpf_object__close(struct bpf_object *obj)
1361{ 1383{
1362 size_t i; 1384 size_t i;