diff mbox series

[bpf-next,v3,2/3] tools: bpftool: keep errors for map-of-map dumps if distinct from ENOENT

Message ID 20200910102652.10509-3-quentin@isovalent.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series tools: bpftool: support creating outer maps | expand

Commit Message

Quentin Monnet Sept. 10, 2020, 10:26 a.m. UTC
When dumping outer maps or prog_array maps, and on lookup failure,
bpftool simply skips the entry with no error message. This is because
the kernel returns non-zero when no value is found for the provided key,
which frequently happen for those maps if they have not been filled.

When such a case occurs, errno is set to ENOENT. It seems unlikely we
could receive other error codes at this stage (we successfully retrieved
map info just before), but to be on the safe side, let's skip the entry
only if errno was ENOENT, and not for the other errors.

v3: New patch

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
---
 tools/bpf/bpftool/map.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andrii Nakryiko Sept. 10, 2020, 4:42 p.m. UTC | #1
On Thu, Sep 10, 2020 at 3:27 AM Quentin Monnet <quentin@isovalent.com> wrote:
>
> When dumping outer maps or prog_array maps, and on lookup failure,
> bpftool simply skips the entry with no error message. This is because
> the kernel returns non-zero when no value is found for the provided key,
> which frequently happen for those maps if they have not been filled.
>
> When such a case occurs, errno is set to ENOENT. It seems unlikely we
> could receive other error codes at this stage (we successfully retrieved
> map info just before), but to be on the safe side, let's skip the entry
> only if errno was ENOENT, and not for the other errors.
>
> v3: New patch
>
> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
> ---
>  tools/bpf/bpftool/map.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index c8159cb4fb1e..d8581d5e98a1 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -240,8 +240,8 @@ print_entry_error(struct bpf_map_info *map_info, void *key, int lookup_errno)
>          * means there is no entry for that key. Do not print an error message
>          * in that case.
>          */
> -       if (map_is_map_of_maps(map_info->type) ||
> -           map_is_map_of_progs(map_info->type))
> +       if ((map_is_map_of_maps(map_info->type) ||
> +            map_is_map_of_progs(map_info->type)) && lookup_errno == ENOENT)
>                 return;


Ah, ok, you decided to split it out into a separate patch. Ok.

Acked-by: Andrii Nakryiko <andriin@fb.com>

>
>         if (json_output) {
> --
> 2.25.1
>
Quentin Monnet Sept. 10, 2020, 4:45 p.m. UTC | #2
On 10/09/2020 17:42, Andrii Nakryiko wrote:
> On Thu, Sep 10, 2020 at 3:27 AM Quentin Monnet <quentin@isovalent.com> wrote:
>>
>> When dumping outer maps or prog_array maps, and on lookup failure,
>> bpftool simply skips the entry with no error message. This is because
>> the kernel returns non-zero when no value is found for the provided key,
>> which frequently happen for those maps if they have not been filled.
>>
>> When such a case occurs, errno is set to ENOENT. It seems unlikely we
>> could receive other error codes at this stage (we successfully retrieved
>> map info just before), but to be on the safe side, let's skip the entry
>> only if errno was ENOENT, and not for the other errors.
>>
>> v3: New patch
>>
>> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
>> ---
>>  tools/bpf/bpftool/map.c | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
>> index c8159cb4fb1e..d8581d5e98a1 100644
>> --- a/tools/bpf/bpftool/map.c
>> +++ b/tools/bpf/bpftool/map.c
>> @@ -240,8 +240,8 @@ print_entry_error(struct bpf_map_info *map_info, void *key, int lookup_errno)
>>          * means there is no entry for that key. Do not print an error message
>>          * in that case.
>>          */
>> -       if (map_is_map_of_maps(map_info->type) ||
>> -           map_is_map_of_progs(map_info->type))
>> +       if ((map_is_map_of_maps(map_info->type) ||
>> +            map_is_map_of_progs(map_info->type)) && lookup_errno == ENOENT)
>>                 return;
> 
> 
> Ah, ok, you decided to split it out into a separate patch. Ok.

Yes, I chose to keep the first one with no functional change to keep the
logs cleaner.

> Acked-by: Andrii Nakryiko <andriin@fb.com>

Thanks!
Quentin
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index c8159cb4fb1e..d8581d5e98a1 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -240,8 +240,8 @@  print_entry_error(struct bpf_map_info *map_info, void *key, int lookup_errno)
 	 * means there is no entry for that key. Do not print an error message
 	 * in that case.
 	 */
-	if (map_is_map_of_maps(map_info->type) ||
-	    map_is_map_of_progs(map_info->type))
+	if ((map_is_map_of_maps(map_info->type) ||
+	     map_is_map_of_progs(map_info->type)) && lookup_errno == ENOENT)
 		return;
 
 	if (json_output) {