[PATCH 07/10] bpf tools: Support BPF_OBJ_PIN and BPF_OBJ_GET
Commit b2197755b2633e164a439682fb05a9b5ea48f706 ("bpf: add support for persistent maps/progs") introduces two new operations to both map and program. This patch makes libbpf support it. Signed-off-by: Wang Nan Cc: Alexei Starovoitov Cc: Arnaldo Carvalho de Melo Cc: Daniel Borkmann --- tools/lib/bpf/bpf.c | 21 + tools/lib/bpf/bpf.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 89c9d0b..5f174c6 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -129,3 +129,24 @@ int bpf_map_get_next_key(int fd, void *key, void *next_key) return sys_bpf(BPF_MAP_GET_NEXT_KEY, , sizeof(attr)); } + +int bpf_pin_object(int fd, const char *pathname) +{ + union bpf_attr attr; + + bzero(, sizeof(attr)); + attr.pathname = ptr_to_u64((void *)pathname); + attr.bpf_fd = fd; + + return sys_bpf(BPF_OBJ_PIN, , sizeof(attr)); +} + +int bpf_get_pinned_object(const char *pathname) +{ + union bpf_attr attr; + + bzero(, sizeof(attr)); + attr.pathname = ptr_to_u64((void *)pathname); + + return sys_bpf(BPF_OBJ_GET, , sizeof(attr)); +} diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 3d22048..c9f1a1c 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -27,4 +27,7 @@ int bpf_map_update_elem(int fd, void *key, void *value, int bpf_map_lookup_elem(int fd, void *key, void *value); int bpf_map_delete_elem(int fd, void *key); int bpf_map_get_next_key(int fd, void *key, void *next_key); + +int bpf_pin_object(int fd, const char *pathname); +int bpf_get_pinned_object(const char *pathname); #endif -- 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[PATCH 07/10] bpf tools: Support BPF_OBJ_PIN and BPF_OBJ_GET
Commit b2197755b2633e164a439682fb05a9b5ea48f706 ("bpf: add support for persistent maps/progs") introduces two new operations to both map and program. This patch makes libbpf support it. Signed-off-by: Wang NanCc: Alexei Starovoitov Cc: Arnaldo Carvalho de Melo Cc: Daniel Borkmann --- tools/lib/bpf/bpf.c | 21 + tools/lib/bpf/bpf.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 89c9d0b..5f174c6 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -129,3 +129,24 @@ int bpf_map_get_next_key(int fd, void *key, void *next_key) return sys_bpf(BPF_MAP_GET_NEXT_KEY, , sizeof(attr)); } + +int bpf_pin_object(int fd, const char *pathname) +{ + union bpf_attr attr; + + bzero(, sizeof(attr)); + attr.pathname = ptr_to_u64((void *)pathname); + attr.bpf_fd = fd; + + return sys_bpf(BPF_OBJ_PIN, , sizeof(attr)); +} + +int bpf_get_pinned_object(const char *pathname) +{ + union bpf_attr attr; + + bzero(, sizeof(attr)); + attr.pathname = ptr_to_u64((void *)pathname); + + return sys_bpf(BPF_OBJ_GET, , sizeof(attr)); +} diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 3d22048..c9f1a1c 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h @@ -27,4 +27,7 @@ int bpf_map_update_elem(int fd, void *key, void *value, int bpf_map_lookup_elem(int fd, void *key, void *value); int bpf_map_delete_elem(int fd, void *key); int bpf_map_get_next_key(int fd, void *key, void *next_key); + +int bpf_pin_object(int fd, const char *pathname); +int bpf_get_pinned_object(const char *pathname); #endif -- 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/