Commit be18010e authored by Kefeng Wang's avatar Kefeng Wang Committed by Daniel Borkmann

tools, bpf: Rename pr_warning to pr_warn to align with kernel logging

For kernel logging macros, pr_warning() is completely removed and
replaced by pr_warn(). By using pr_warn() in tools/lib/bpf/ for
symmetry to kernel logging macros, we could eventually drop the
use of pr_warning() in the whole kernel tree.
Signed-off-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20191021055532.185245-1-wangkefeng.wang@huawei.com
parent ab81e203
...@@ -390,14 +390,14 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext) ...@@ -390,14 +390,14 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext)
GElf_Ehdr ehdr; GElf_Ehdr ehdr;
if (elf_version(EV_CURRENT) == EV_NONE) { if (elf_version(EV_CURRENT) == EV_NONE) {
pr_warning("failed to init libelf for %s\n", path); pr_warn("failed to init libelf for %s\n", path);
return ERR_PTR(-LIBBPF_ERRNO__LIBELF); return ERR_PTR(-LIBBPF_ERRNO__LIBELF);
} }
fd = open(path, O_RDONLY); fd = open(path, O_RDONLY);
if (fd < 0) { if (fd < 0) {
err = -errno; err = -errno;
pr_warning("failed to open %s: %s\n", path, strerror(errno)); pr_warn("failed to open %s: %s\n", path, strerror(errno));
return ERR_PTR(err); return ERR_PTR(err);
} }
...@@ -405,19 +405,19 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext) ...@@ -405,19 +405,19 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext)
elf = elf_begin(fd, ELF_C_READ, NULL); elf = elf_begin(fd, ELF_C_READ, NULL);
if (!elf) { if (!elf) {
pr_warning("failed to open %s as ELF file\n", path); pr_warn("failed to open %s as ELF file\n", path);
goto done; goto done;
} }
if (!gelf_getehdr(elf, &ehdr)) { if (!gelf_getehdr(elf, &ehdr)) {
pr_warning("failed to get EHDR from %s\n", path); pr_warn("failed to get EHDR from %s\n", path);
goto done; goto done;
} }
if (!btf_check_endianness(&ehdr)) { if (!btf_check_endianness(&ehdr)) {
pr_warning("non-native ELF endianness is not supported\n"); pr_warn("non-native ELF endianness is not supported\n");
goto done; goto done;
} }
if (!elf_rawdata(elf_getscn(elf, ehdr.e_shstrndx), NULL)) { if (!elf_rawdata(elf_getscn(elf, ehdr.e_shstrndx), NULL)) {
pr_warning("failed to get e_shstrndx from %s\n", path); pr_warn("failed to get e_shstrndx from %s\n", path);
goto done; goto done;
} }
...@@ -427,29 +427,29 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext) ...@@ -427,29 +427,29 @@ struct btf *btf__parse_elf(const char *path, struct btf_ext **btf_ext)
idx++; idx++;
if (gelf_getshdr(scn, &sh) != &sh) { if (gelf_getshdr(scn, &sh) != &sh) {
pr_warning("failed to get section(%d) header from %s\n", pr_warn("failed to get section(%d) header from %s\n",
idx, path); idx, path);
goto done; goto done;
} }
name = elf_strptr(elf, ehdr.e_shstrndx, sh.sh_name); name = elf_strptr(elf, ehdr.e_shstrndx, sh.sh_name);
if (!name) { if (!name) {
pr_warning("failed to get section(%d) name from %s\n", pr_warn("failed to get section(%d) name from %s\n",
idx, path); idx, path);
goto done; goto done;
} }
if (strcmp(name, BTF_ELF_SEC) == 0) { if (strcmp(name, BTF_ELF_SEC) == 0) {
btf_data = elf_getdata(scn, 0); btf_data = elf_getdata(scn, 0);
if (!btf_data) { if (!btf_data) {
pr_warning("failed to get section(%d, %s) data from %s\n", pr_warn("failed to get section(%d, %s) data from %s\n",
idx, name, path); idx, name, path);
goto done; goto done;
} }
continue; continue;
} else if (btf_ext && strcmp(name, BTF_EXT_ELF_SEC) == 0) { } else if (btf_ext && strcmp(name, BTF_EXT_ELF_SEC) == 0) {
btf_ext_data = elf_getdata(scn, 0); btf_ext_data = elf_getdata(scn, 0);
if (!btf_ext_data) { if (!btf_ext_data) {
pr_warning("failed to get section(%d, %s) data from %s\n", pr_warn("failed to get section(%d, %s) data from %s\n",
idx, name, path); idx, name, path);
goto done; goto done;
} }
continue; continue;
...@@ -600,9 +600,9 @@ int btf__load(struct btf *btf) ...@@ -600,9 +600,9 @@ int btf__load(struct btf *btf)
log_buf, log_buf_size, false); log_buf, log_buf_size, false);
if (btf->fd < 0) { if (btf->fd < 0) {
err = -errno; err = -errno;
pr_warning("Error loading BTF: %s(%d)\n", strerror(errno), errno); pr_warn("Error loading BTF: %s(%d)\n", strerror(errno), errno);
if (*log_buf) if (*log_buf)
pr_warning("%s\n", log_buf); pr_warn("%s\n", log_buf);
goto done; goto done;
} }
...@@ -707,8 +707,8 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, ...@@ -707,8 +707,8 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
if (snprintf(container_name, max_name, "____btf_map_%s", map_name) == if (snprintf(container_name, max_name, "____btf_map_%s", map_name) ==
max_name) { max_name) {
pr_warning("map:%s length of '____btf_map_%s' is too long\n", pr_warn("map:%s length of '____btf_map_%s' is too long\n",
map_name, map_name); map_name, map_name);
return -EINVAL; return -EINVAL;
} }
...@@ -721,14 +721,14 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, ...@@ -721,14 +721,14 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
container_type = btf__type_by_id(btf, container_id); container_type = btf__type_by_id(btf, container_id);
if (!container_type) { if (!container_type) {
pr_warning("map:%s cannot find BTF type for container_id:%u\n", pr_warn("map:%s cannot find BTF type for container_id:%u\n",
map_name, container_id); map_name, container_id);
return -EINVAL; return -EINVAL;
} }
if (!btf_is_struct(container_type) || btf_vlen(container_type) < 2) { if (!btf_is_struct(container_type) || btf_vlen(container_type) < 2) {
pr_warning("map:%s container_name:%s is an invalid container struct\n", pr_warn("map:%s container_name:%s is an invalid container struct\n",
map_name, container_name); map_name, container_name);
return -EINVAL; return -EINVAL;
} }
...@@ -737,25 +737,25 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, ...@@ -737,25 +737,25 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name,
key_size = btf__resolve_size(btf, key->type); key_size = btf__resolve_size(btf, key->type);
if (key_size < 0) { if (key_size < 0) {
pr_warning("map:%s invalid BTF key_type_size\n", map_name); pr_warn("map:%s invalid BTF key_type_size\n", map_name);
return key_size; return key_size;
} }
if (expected_key_size != key_size) { if (expected_key_size != key_size) {
pr_warning("map:%s btf_key_type_size:%u != map_def_key_size:%u\n", pr_warn("map:%s btf_key_type_size:%u != map_def_key_size:%u\n",
map_name, (__u32)key_size, expected_key_size); map_name, (__u32)key_size, expected_key_size);
return -EINVAL; return -EINVAL;
} }
value_size = btf__resolve_size(btf, value->type); value_size = btf__resolve_size(btf, value->type);
if (value_size < 0) { if (value_size < 0) {
pr_warning("map:%s invalid BTF value_type_size\n", map_name); pr_warn("map:%s invalid BTF value_type_size\n", map_name);
return value_size; return value_size;
} }
if (expected_value_size != value_size) { if (expected_value_size != value_size) {
pr_warning("map:%s btf_value_type_size:%u != map_def_value_size:%u\n", pr_warn("map:%s btf_value_type_size:%u != map_def_value_size:%u\n",
map_name, (__u32)value_size, expected_value_size); map_name, (__u32)value_size, expected_value_size);
return -EINVAL; return -EINVAL;
} }
......
...@@ -428,7 +428,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) ...@@ -428,7 +428,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr)
/* type loop, but resolvable through fwd declaration */ /* type loop, but resolvable through fwd declaration */
if (btf_is_composite(t) && through_ptr && t->name_off != 0) if (btf_is_composite(t) && through_ptr && t->name_off != 0)
return 0; return 0;
pr_warning("unsatisfiable type cycle, id:[%u]\n", id); pr_warn("unsatisfiable type cycle, id:[%u]\n", id);
return -ELOOP; return -ELOOP;
} }
...@@ -636,8 +636,8 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) ...@@ -636,8 +636,8 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id)
if (id == cont_id) if (id == cont_id)
return; return;
if (t->name_off == 0) { if (t->name_off == 0) {
pr_warning("anonymous struct/union loop, id:[%u]\n", pr_warn("anonymous struct/union loop, id:[%u]\n",
id); id);
return; return;
} }
btf_dump_emit_struct_fwd(d, id, t); btf_dump_emit_struct_fwd(d, id, t);
...@@ -782,7 +782,7 @@ static int btf_align_of(const struct btf *btf, __u32 id) ...@@ -782,7 +782,7 @@ static int btf_align_of(const struct btf *btf, __u32 id)
return align; return align;
} }
default: default:
pr_warning("unsupported BTF_KIND:%u\n", btf_kind(t)); pr_warn("unsupported BTF_KIND:%u\n", btf_kind(t));
return 1; return 1;
} }
} }
...@@ -1067,7 +1067,7 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, ...@@ -1067,7 +1067,7 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
* chain, restore stack, emit warning, and try to * chain, restore stack, emit warning, and try to
* proceed nevertheless * proceed nevertheless
*/ */
pr_warning("not enough memory for decl stack:%d", err); pr_warn("not enough memory for decl stack:%d", err);
d->decl_stack_cnt = stack_start; d->decl_stack_cnt = stack_start;
return; return;
} }
...@@ -1096,8 +1096,8 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, ...@@ -1096,8 +1096,8 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
case BTF_KIND_TYPEDEF: case BTF_KIND_TYPEDEF:
goto done; goto done;
default: default:
pr_warning("unexpected type in decl chain, kind:%u, id:[%u]\n", pr_warn("unexpected type in decl chain, kind:%u, id:[%u]\n",
btf_kind(t), id); btf_kind(t), id);
goto done; goto done;
} }
} }
...@@ -1323,8 +1323,8 @@ static void btf_dump_emit_type_chain(struct btf_dump *d, ...@@ -1323,8 +1323,8 @@ static void btf_dump_emit_type_chain(struct btf_dump *d,
return; return;
} }
default: default:
pr_warning("unexpected type in decl chain, kind:%u, id:[%u]\n", pr_warn("unexpected type in decl chain, kind:%u, id:[%u]\n",
kind, id); kind, id);
return; return;
} }
......
This diff is collapsed.
...@@ -43,7 +43,7 @@ do { \ ...@@ -43,7 +43,7 @@ do { \
libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \ libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \
} while (0) } while (0)
#define pr_warning(fmt, ...) __pr(LIBBPF_WARN, fmt, ##__VA_ARGS__) #define pr_warn(fmt, ...) __pr(LIBBPF_WARN, fmt, ##__VA_ARGS__)
#define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__) #define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__)
#define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__) #define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__)
...@@ -52,7 +52,7 @@ static inline bool libbpf_validate_opts(const char *opts, ...@@ -52,7 +52,7 @@ static inline bool libbpf_validate_opts(const char *opts,
const char *type_name) const char *type_name)
{ {
if (user_sz < sizeof(size_t)) { if (user_sz < sizeof(size_t)) {
pr_warning("%s size (%zu) is too small\n", type_name, user_sz); pr_warn("%s size (%zu) is too small\n", type_name, user_sz);
return false; return false;
} }
if (user_sz > opts_sz) { if (user_sz > opts_sz) {
...@@ -60,8 +60,8 @@ static inline bool libbpf_validate_opts(const char *opts, ...@@ -60,8 +60,8 @@ static inline bool libbpf_validate_opts(const char *opts,
for (i = opts_sz; i < user_sz; i++) { for (i = opts_sz; i < user_sz; i++) {
if (opts[i]) { if (opts[i]) {
pr_warning("%s has non-zero extra bytes", pr_warn("%s has non-zero extra bytes",
type_name); type_name);
return false; return false;
} }
} }
......
...@@ -311,7 +311,7 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk) ...@@ -311,7 +311,7 @@ static int xsk_load_xdp_prog(struct xsk_socket *xsk)
"LGPL-2.1 or BSD-2-Clause", 0, log_buf, "LGPL-2.1 or BSD-2-Clause", 0, log_buf,
log_buf_size); log_buf_size);
if (prog_fd < 0) { if (prog_fd < 0) {
pr_warning("BPF log buffer:\n%s", log_buf); pr_warn("BPF log buffer:\n%s", log_buf);
return prog_fd; return prog_fd;
} }
...@@ -499,7 +499,7 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname, ...@@ -499,7 +499,7 @@ int xsk_socket__create(struct xsk_socket **xsk_ptr, const char *ifname,
return -EFAULT; return -EFAULT;
if (umem->refcount) { if (umem->refcount) {
pr_warning("Error: shared umems not supported by libbpf.\n"); pr_warn("Error: shared umems not supported by libbpf.\n");
return -EBUSY; return -EBUSY;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment