aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorAndrey Ignatov <rdna@fb.com>2018-10-03 18:26:41 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-10-04 10:04:16 -0400
commit24d6a8084259e22acf9a80d4de3606a031f42f6d (patch)
tree83b8a37d3bb78e8cf2a0ea90ebe88faeb4c5eb90 /tools/lib/bpf
parentf04bc8a436e1b32f842a631ff889954bdf56b720 (diff)
libbpf: Consistent prefixes for interfaces in str_error.h.
libbpf is used more and more outside kernel tree. That means the library should follow good practices in library design and implementation to play well with third party code that uses it. One of such practices is to have a common prefix (or a few) for every interface, function or data structure, library provides. I helps to avoid name conflicts with other libraries and keeps API consistent. Inconsistent names in libbpf already cause problems in real life. E.g. an application can't use both libbpf and libnl due to conflicting symbols. Having common prefix will help to fix current and avoid future problems. libbpf already uses the following prefixes for its interfaces: * bpf_ for bpf system call wrappers, program/map/elf-object abstractions and a few other things; * btf_ for BTF related API; * libbpf_ for everything else. The patch renames function in str_error.h to have libbpf_ prefix since it misses one and doesn't fit well into the first two categories. Signed-off-by: Andrey Ignatov <rdna@fb.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/libbpf.c20
-rw-r--r--tools/lib/bpf/str_error.c2
-rw-r--r--tools/lib/bpf/str_error.h2
3 files changed, 13 insertions, 11 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 9e68fd9fcfca..02888d36b805 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -470,7 +470,8 @@ static int bpf_object__elf_init(struct bpf_object *obj)
470 obj->efile.fd = open(obj->path, O_RDONLY); 470 obj->efile.fd = open(obj->path, O_RDONLY);
471 if (obj->efile.fd < 0) { 471 if (obj->efile.fd < 0) {
472 char errmsg[STRERR_BUFSIZE]; 472 char errmsg[STRERR_BUFSIZE];
473 char *cp = str_error(errno, errmsg, sizeof(errmsg)); 473 char *cp = libbpf_strerror_r(errno, errmsg,
474 sizeof(errmsg));
474 475
475 pr_warning("failed to open %s: %s\n", obj->path, cp); 476 pr_warning("failed to open %s: %s\n", obj->path, cp);
476 return -errno; 477 return -errno;
@@ -811,7 +812,8 @@ static int bpf_object__elf_collect(struct bpf_object *obj)
811 data->d_size, name, idx); 812 data->d_size, name, idx);
812 if (err) { 813 if (err) {
813 char errmsg[STRERR_BUFSIZE]; 814 char errmsg[STRERR_BUFSIZE];
814 char *cp = str_error(-err, errmsg, sizeof(errmsg)); 815 char *cp = libbpf_strerror_r(-err, errmsg,
816 sizeof(errmsg));
815 817
816 pr_warning("failed to alloc program %s (%s): %s", 818 pr_warning("failed to alloc program %s (%s): %s",
817 name, obj->path, cp); 819 name, obj->path, cp);
@@ -1140,7 +1142,7 @@ bpf_object__create_maps(struct bpf_object *obj)
1140 1142
1141 *pfd = bpf_create_map_xattr(&create_attr); 1143 *pfd = bpf_create_map_xattr(&create_attr);
1142 if (*pfd < 0 && create_attr.btf_key_type_id) { 1144 if (*pfd < 0 && create_attr.btf_key_type_id) {
1143 cp = str_error(errno, errmsg, sizeof(errmsg)); 1145 cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
1144 pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n", 1146 pr_warning("Error in bpf_create_map_xattr(%s):%s(%d). Retrying without BTF.\n",
1145 map->name, cp, errno); 1147 map->name, cp, errno);
1146 create_attr.btf_fd = 0; 1148 create_attr.btf_fd = 0;
@@ -1155,7 +1157,7 @@ bpf_object__create_maps(struct bpf_object *obj)
1155 size_t j; 1157 size_t j;
1156 1158
1157 err = *pfd; 1159 err = *pfd;
1158 cp = str_error(errno, errmsg, sizeof(errmsg)); 1160 cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
1159 pr_warning("failed to create map (name: '%s'): %s\n", 1161 pr_warning("failed to create map (name: '%s'): %s\n",
1160 map->name, cp); 1162 map->name, cp);
1161 for (j = 0; j < i; j++) 1163 for (j = 0; j < i; j++)
@@ -1339,7 +1341,7 @@ load_program(enum bpf_prog_type type, enum bpf_attach_type expected_attach_type,
1339 } 1341 }
1340 1342
1341 ret = -LIBBPF_ERRNO__LOAD; 1343 ret = -LIBBPF_ERRNO__LOAD;
1342 cp = str_error(errno, errmsg, sizeof(errmsg)); 1344 cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
1343 pr_warning("load bpf program failed: %s\n", cp); 1345 pr_warning("load bpf program failed: %s\n", cp);
1344 1346
1345 if (log_buf && log_buf[0] != '\0') { 1347 if (log_buf && log_buf[0] != '\0') {
@@ -1655,7 +1657,7 @@ static int check_path(const char *path)
1655 1657
1656 dir = dirname(dname); 1658 dir = dirname(dname);
1657 if (statfs(dir, &st_fs)) { 1659 if (statfs(dir, &st_fs)) {
1658 cp = str_error(errno, errmsg, sizeof(errmsg)); 1660 cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
1659 pr_warning("failed to statfs %s: %s\n", dir, cp); 1661 pr_warning("failed to statfs %s: %s\n", dir, cp);
1660 err = -errno; 1662 err = -errno;
1661 } 1663 }
@@ -1691,7 +1693,7 @@ int bpf_program__pin_instance(struct bpf_program *prog, const char *path,
1691 } 1693 }
1692 1694
1693 if (bpf_obj_pin(prog->instances.fds[instance], path)) { 1695 if (bpf_obj_pin(prog->instances.fds[instance], path)) {
1694 cp = str_error(errno, errmsg, sizeof(errmsg)); 1696 cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
1695 pr_warning("failed to pin program: %s\n", cp); 1697 pr_warning("failed to pin program: %s\n", cp);
1696 return -errno; 1698 return -errno;
1697 } 1699 }
@@ -1709,7 +1711,7 @@ static int make_dir(const char *path)
1709 err = -errno; 1711 err = -errno;
1710 1712
1711 if (err) { 1713 if (err) {
1712 cp = str_error(-err, errmsg, sizeof(errmsg)); 1714 cp = libbpf_strerror_r(-err, errmsg, sizeof(errmsg));
1713 pr_warning("failed to mkdir %s: %s\n", path, cp); 1715 pr_warning("failed to mkdir %s: %s\n", path, cp);
1714 } 1716 }
1715 return err; 1717 return err;
@@ -1771,7 +1773,7 @@ int bpf_map__pin(struct bpf_map *map, const char *path)
1771 } 1773 }
1772 1774
1773 if (bpf_obj_pin(map->fd, path)) { 1775 if (bpf_obj_pin(map->fd, path)) {
1774 cp = str_error(errno, errmsg, sizeof(errmsg)); 1776 cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
1775 pr_warning("failed to pin map: %s\n", cp); 1777 pr_warning("failed to pin map: %s\n", cp);
1776 return -errno; 1778 return -errno;
1777 } 1779 }
diff --git a/tools/lib/bpf/str_error.c b/tools/lib/bpf/str_error.c
index b8798114a357..3d211b642cb5 100644
--- a/tools/lib/bpf/str_error.c
+++ b/tools/lib/bpf/str_error.c
@@ -9,7 +9,7 @@
9 * libc, while checking strerror_r() return to avoid having to check this in 9 * libc, while checking strerror_r() return to avoid having to check this in
10 * all places calling it. 10 * all places calling it.
11 */ 11 */
12char *str_error(int err, char *dst, int len) 12char *libbpf_strerror_r(int err, char *dst, int len)
13{ 13{
14 int ret = strerror_r(err, dst, len); 14 int ret = strerror_r(err, dst, len);
15 if (ret) 15 if (ret)
diff --git a/tools/lib/bpf/str_error.h b/tools/lib/bpf/str_error.h
index 355b1db571d1..998eff7d6710 100644
--- a/tools/lib/bpf/str_error.h
+++ b/tools/lib/bpf/str_error.h
@@ -2,5 +2,5 @@
2#ifndef BPF_STR_ERROR 2#ifndef BPF_STR_ERROR
3#define BPF_STR_ERROR 3#define BPF_STR_ERROR
4 4
5char *str_error(int err, char *dst, int len); 5char *libbpf_strerror_r(int err, char *dst, int len);
6#endif // BPF_STR_ERROR 6#endif // BPF_STR_ERROR