diff mbox series

[v2,bpf-next,2/2] bpftool: Improve handling of ENOSPC on reuseport_array map dumps

Message ID 20190412030322.15494-2-bpoirier@suse.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series [v2,bpf-next,1/2] bpftool: Use print_entry_error() in case of ENOENT when dumping | expand

Commit Message

Benjamin Poirier April 12, 2019, 3:03 a.m. UTC
avoids outputting a series of
	value:
	No space left on device

The value itself is not wrong but bpf_fd_reuseport_array_lookup_elem() can
only return it if the map was created with value_size = 8. There's nothing
bpftool can do about it. Instead of repeating this error for every key in
the map, print an explanatory warning and a specialized error.

example before:
key: 00 00 00 00
value:
No space left on device
key: 01 00 00 00
value:
No space left on device
key: 02 00 00 00
value:
No space left on device
Found 0 elements

example after:
Warning: cannot read values from reuseport_sockarray map with value_size != 8
key: 00 00 00 00  value: <cannot read>
key: 01 00 00 00  value: <cannot read>
key: 02 00 00 00  value: <cannot read>
Found 0 elements

Signed-off-by: Benjamin Poirier <bpoirier@suse.com>
---
 tools/bpf/bpftool/map.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Quentin Monnet April 12, 2019, 10:28 a.m. UTC | #1
2019-04-12 12:03 UTC+0900 ~ Benjamin Poirier <bpoirier@suse.com>
> avoids outputting a series of
> 	value:
> 	No space left on device
> 
> The value itself is not wrong but bpf_fd_reuseport_array_lookup_elem() can
> only return it if the map was created with value_size = 8. There's nothing
> bpftool can do about it. Instead of repeating this error for every key in
> the map, print an explanatory warning and a specialized error.
> 
> example before:
> key: 00 00 00 00
> value:
> No space left on device
> key: 01 00 00 00
> value:
> No space left on device
> key: 02 00 00 00
> value:
> No space left on device
> Found 0 elements
> 
> example after:
> Warning: cannot read values from reuseport_sockarray map with value_size != 8
> key: 00 00 00 00  value: <cannot read>
> key: 01 00 00 00  value: <cannot read>
> key: 02 00 00 00  value: <cannot read>
> Found 0 elements
> 
> Signed-off-by: Benjamin Poirier <bpoirier@suse.com>
> ---
>   tools/bpf/bpftool/map.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index 71840faaeab5..e6d72f777767 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -716,8 +716,12 @@ static int dump_map_elem(int fd, void *key, void *value,
>   	} else {
>   		const char *msg = NULL;
>   
> -		if (errno == ENOENT)
> +		if (lookup_errno == ENOENT) {
>   			msg = "<no entry>";
> +		} else if (lookup_errno == ENOSPC && map_info->type ==
> +			 BPF_MAP_TYPE_REUSEPORT_SOCKARRAY) {

Nit: This should be aligned on the open parenthesis (And preferably 
split after the "&&", if the second condition fits on its own line?).

Thanks for the changes! This version looks much better to me than v1.

Quentin
Jakub Kicinski April 13, 2019, midnight UTC | #2
On Fri, 12 Apr 2019 12:03:22 +0900, Benjamin Poirier wrote:
> avoids outputting a series of
> 	value:
> 	No space left on device
> 
> The value itself is not wrong but bpf_fd_reuseport_array_lookup_elem() can
> only return it if the map was created with value_size = 8. There's nothing
> bpftool can do about it. Instead of repeating this error for every key in
> the map, print an explanatory warning and a specialized error.
> 
> example before:
> key: 00 00 00 00
> value:
> No space left on device
> key: 01 00 00 00
> value:
> No space left on device
> key: 02 00 00 00
> value:
> No space left on device
> Found 0 elements
> 
> example after:
> Warning: cannot read values from reuseport_sockarray map with value_size != 8
> key: 00 00 00 00  value: <cannot read>
> key: 01 00 00 00  value: <cannot read>
> key: 02 00 00 00  value: <cannot read>
> Found 0 elements
> 
> Signed-off-by: Benjamin Poirier <bpoirier@suse.com>
> ---
>  tools/bpf/bpftool/map.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index 71840faaeab5..e6d72f777767 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -716,8 +716,12 @@ static int dump_map_elem(int fd, void *key, void *value,
>  	} else {
>  		const char *msg = NULL;
>  
> -		if (errno == ENOENT)
> +		if (lookup_errno == ENOENT) {
>  			msg = "<no entry>";
> +		} else if (lookup_errno == ENOSPC && map_info->type ==
> +			 BPF_MAP_TYPE_REUSEPORT_SOCKARRAY) {
> +			msg = "<cannot read>";
> +		}

In addition to Quentin's nit please don't use the curly brackets for
single-line statements.

>  		print_entry_error(map_info, key,
>  				  msg ? : strerror(lookup_errno), !!msg);
> @@ -774,6 +778,11 @@ static int do_dump(int argc, char **argv)
>  			}
>  		}
>  
> +	if (info.type == BPF_MAP_TYPE_REUSEPORT_SOCKARRAY &&
> +	    info.value_size != 8) {
> +		p_info("Warning: cannot read values from %s map with value_size != 8",
> +		       map_type_name[info.type]);
> +	}

Same here :)

>  	while (true) {
>  		err = bpf_map_get_next_key(fd, prev_key, key);
>  		if (err) {
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index 71840faaeab5..e6d72f777767 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -716,8 +716,12 @@  static int dump_map_elem(int fd, void *key, void *value,
 	} else {
 		const char *msg = NULL;
 
-		if (errno == ENOENT)
+		if (lookup_errno == ENOENT) {
 			msg = "<no entry>";
+		} else if (lookup_errno == ENOSPC && map_info->type ==
+			 BPF_MAP_TYPE_REUSEPORT_SOCKARRAY) {
+			msg = "<cannot read>";
+		}
 
 		print_entry_error(map_info, key,
 				  msg ? : strerror(lookup_errno), !!msg);
@@ -774,6 +778,11 @@  static int do_dump(int argc, char **argv)
 			}
 		}
 
+	if (info.type == BPF_MAP_TYPE_REUSEPORT_SOCKARRAY &&
+	    info.value_size != 8) {
+		p_info("Warning: cannot read values from %s map with value_size != 8",
+		       map_type_name[info.type]);
+	}
 	while (true) {
 		err = bpf_map_get_next_key(fd, prev_key, key);
 		if (err) {