[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAEf4BzZZce3evrwkjQ1EbiHo5b_QKWn1kvCkZ=04X594Ee9RjA@mail.gmail.com>
Date: Thu, 10 Sep 2020 09:41:54 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Quentin Monnet <quentin@...valent.com>
Cc: Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
bpf <bpf@...r.kernel.org>, Networking <netdev@...r.kernel.org>
Subject: Re: [PATCH bpf-next v3 1/3] tools: bpftool: clean up function to dump
map entry
On Thu, Sep 10, 2020 at 3:27 AM Quentin Monnet <quentin@...valent.com> wrote:
>
> The function used to dump a map entry in bpftool is a bit difficult to
> follow, as a consequence to earlier refactorings. There is a variable
> ("num_elems") which does not appear to be necessary, and the error
> handling would look cleaner if moved to its own function. Let's clean it
> up. No functional change.
>
> v2:
> - v1 was erroneously removing the check on fd maps in an attempt to get
> support for outer map dumps. This is already working. Instead, v2
> focuses on cleaning up the dump_map_elem() function, to avoid
> similar confusion in the future.
>
> Signed-off-by: Quentin Monnet <quentin@...valent.com>
> ---
> tools/bpf/bpftool/map.c | 101 +++++++++++++++++++++-------------------
> 1 file changed, 52 insertions(+), 49 deletions(-)
>
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index bc0071228f88..c8159cb4fb1e 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -213,8 +213,9 @@ static void print_entry_json(struct bpf_map_info *info, unsigned char *key,
> jsonw_end_object(json_wtr);
> }
>
> -static void print_entry_error(struct bpf_map_info *info, unsigned char *key,
> - const char *error_msg)
> +static void
> +print_entry_error_msg(struct bpf_map_info *info, unsigned char *key,
> + const char *error_msg)
> {
> int msg_size = strlen(error_msg);
> bool single_line, break_names;
> @@ -232,6 +233,40 @@ static void print_entry_error(struct bpf_map_info *info, unsigned char *key,
> printf("\n");
> }
>
> +static void
> +print_entry_error(struct bpf_map_info *map_info, void *key, int lookup_errno)
> +{
> + /* For prog_array maps or arrays of maps, failure to lookup the value
> + * 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))
&& lookup_errno == ENOENT
?
> + return;
> +
[...]
Powered by blists - more mailing lists