diff options
author | Benjamin Poirier <bpoirier@suse.com> | 2019-04-15 03:15:35 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-04-16 04:16:33 -0400 |
commit | 0478c3bf812451315da6eeb79f8cf151db094767 (patch) | |
tree | cfd4f4a5b2dbb7c21000fecba7ee568df87353f0 /tools/bpf/bpftool | |
parent | 25df480def17eb792860d86b8f90fda00035f0f9 (diff) |
bpftool: Use print_entry_error() in case of ENOENT when dumping
Commit bf598a8f0f77 ("bpftool: Improve handling of ENOENT on map dumps")
used print_entry_plain() in case of ENOENT. However, that commit introduces
dead code. Per-cpu maps are zero-filled. When reading them, it's all or
nothing. There will never be a case where some cpus have an entry and
others don't.
The truth is that ENOENT is an error case. Use print_entry_error() to
output the desired message. That function's "value" parameter is also
renamed to indicate that we never use it for an actual map value.
The output format is unchanged.
Signed-off-by: Benjamin Poirier <bpoirier@suse.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/bpf/bpftool')
-rw-r--r-- | tools/bpf/bpftool/map.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c index e96903078991..df958af56b6c 100644 --- a/tools/bpf/bpftool/map.c +++ b/tools/bpf/bpftool/map.c | |||
@@ -261,20 +261,20 @@ static void print_entry_json(struct bpf_map_info *info, unsigned char *key, | |||
261 | } | 261 | } |
262 | 262 | ||
263 | static void print_entry_error(struct bpf_map_info *info, unsigned char *key, | 263 | static void print_entry_error(struct bpf_map_info *info, unsigned char *key, |
264 | const char *value) | 264 | const char *error_msg) |
265 | { | 265 | { |
266 | int value_size = strlen(value); | 266 | int msg_size = strlen(error_msg); |
267 | bool single_line, break_names; | 267 | bool single_line, break_names; |
268 | 268 | ||
269 | break_names = info->key_size > 16 || value_size > 16; | 269 | break_names = info->key_size > 16 || msg_size > 16; |
270 | single_line = info->key_size + value_size <= 24 && !break_names; | 270 | single_line = info->key_size + msg_size <= 24 && !break_names; |
271 | 271 | ||
272 | printf("key:%c", break_names ? '\n' : ' '); | 272 | printf("key:%c", break_names ? '\n' : ' '); |
273 | fprint_hex(stdout, key, info->key_size, " "); | 273 | fprint_hex(stdout, key, info->key_size, " "); |
274 | 274 | ||
275 | printf(single_line ? " " : "\n"); | 275 | printf(single_line ? " " : "\n"); |
276 | 276 | ||
277 | printf("value:%c%s", break_names ? '\n' : ' ', value); | 277 | printf("value:%c%s", break_names ? '\n' : ' ', error_msg); |
278 | 278 | ||
279 | printf("\n"); | 279 | printf("\n"); |
280 | } | 280 | } |
@@ -298,11 +298,7 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, | |||
298 | 298 | ||
299 | if (info->value_size) { | 299 | if (info->value_size) { |
300 | printf("value:%c", break_names ? '\n' : ' '); | 300 | printf("value:%c", break_names ? '\n' : ' '); |
301 | if (value) | 301 | fprint_hex(stdout, value, info->value_size, " "); |
302 | fprint_hex(stdout, value, info->value_size, | ||
303 | " "); | ||
304 | else | ||
305 | printf("<no entry>"); | ||
306 | } | 302 | } |
307 | 303 | ||
308 | printf("\n"); | 304 | printf("\n"); |
@@ -321,11 +317,8 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, | |||
321 | for (i = 0; i < n; i++) { | 317 | for (i = 0; i < n; i++) { |
322 | printf("value (CPU %02d):%c", | 318 | printf("value (CPU %02d):%c", |
323 | i, info->value_size > 16 ? '\n' : ' '); | 319 | i, info->value_size > 16 ? '\n' : ' '); |
324 | if (value) | 320 | fprint_hex(stdout, value + i * step, |
325 | fprint_hex(stdout, value + i * step, | 321 | info->value_size, " "); |
326 | info->value_size, " "); | ||
327 | else | ||
328 | printf("<no entry>"); | ||
329 | printf("\n"); | 322 | printf("\n"); |
330 | } | 323 | } |
331 | } | 324 | } |
@@ -722,11 +715,13 @@ static int dump_map_elem(int fd, void *key, void *value, | |||
722 | jsonw_string_field(json_wtr, "error", strerror(lookup_errno)); | 715 | jsonw_string_field(json_wtr, "error", strerror(lookup_errno)); |
723 | jsonw_end_object(json_wtr); | 716 | jsonw_end_object(json_wtr); |
724 | } else { | 717 | } else { |
718 | const char *msg = NULL; | ||
719 | |||
725 | if (errno == ENOENT) | 720 | if (errno == ENOENT) |
726 | print_entry_plain(map_info, key, NULL); | 721 | msg = "<no entry>"; |
727 | else | 722 | |
728 | print_entry_error(map_info, key, | 723 | print_entry_error(map_info, key, |
729 | strerror(lookup_errno)); | 724 | msg ? : strerror(lookup_errno)); |
730 | } | 725 | } |
731 | 726 | ||
732 | return 0; | 727 | return 0; |