BPF List
 help / color / mirror / Atom feed
From: Quentin Monnet <qmo@kernel.org>
To: Tianyi Chen <hi@tychen.cc>, bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
	eddyz87@gmail.com, memxor@gmail.com, shuah@kernel.org,
	linux-kselftest@vger.kernel.org, ihor.solodrai@linux.dev
Subject: Re: [PATCH bpf-next v12 2/3] bpftool: Add recursive map dumping
Date: Wed, 11 Nov 2026 16:24:48 +0000	[thread overview]
Message-ID: <447aeaaa-dd74-47c2-b517-790ae98e8962@kernel.org> (raw)
In-Reply-To: <237281e76007092c3cd8debdc8dddce418f7354b.1794380385.git.hi@tychen.cc>

2026-11-11 16:19 UTC+0900 ~ Tianyi Chen <hi@tychen.cc>
> Dumping an array_of_maps or a hash_of_maps shows the IDs of the inner
> maps but not their contents. Add a recursive keyword to map dump that
> also dumps each inner map in the entry that references it. JSON gains
> an "inner_map" object next to "inner_map_id". Plain output separates
> inner maps with blank lines and indents their raw entries and element
> counts. Output without the keyword is unchanged.
> 
> The kernel permits only one map-in-map level. Look up outer entries
> individually, then open, dump and close each referenced inner map
> immediately. This uses one extra map FD; inner dumps may still use batch
> lookups. Shared inner maps are dumped at every referring entry. If an
> inner map has disappeared, report the error in that entry and continue.
> 
> Link: https://github.com/libbpf/bpftool/issues/58
> Suggested-by: Alexei Starovoitov <ast@kernel.org>
> Assisted-by: LLM
> Signed-off-by: Tianyi Chen <hi@tychen.cc>
> ---
>  .../bpf/bpftool/Documentation/bpftool-map.rst |  10 +-
>  tools/bpf/bpftool/bash-completion/bpftool     |   3 +
>  tools/bpf/bpftool/map.c                       | 123 +++++++++++++++---
>  3 files changed, 113 insertions(+), 23 deletions(-)
> 

[...]

> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index 9e4dc3881060..79d33af257b6 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c

[...]

> @@ -1003,6 +1036,43 @@ map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
>  	return err;
>  }
>  
> +/* The kernel has one level of map-in-map: inner maps have no inner maps. */
> +static void dump_inner_map(__u32 id)
> +{
> +	LIBBPF_OPTS(bpf_get_fd_by_id_opts, opts, .open_flags = BPF_F_RDONLY);
> +	struct bpf_map_info info = {};
> +	json_writer_t *btf_wtr = NULL;
> +	__u32 len = sizeof(info);
> +	int fd;
> +
> +	fd = bpf_map_get_fd_by_id_opts(id, &opts);
> +	if (fd < 0) {
> +		p_err("can't get map by id (%u): %s", id, strerror(errno));
> +		return;
> +	}
> +	if (bpf_map_get_info_by_fd(fd, &info, &len)) {
> +		p_err("can't get map info: %s", strerror(errno));
> +		goto out;
> +	}
> +
> +	if (!json_output && info.btf_value_type_id)
> +		btf_wtr = get_btf_writer();


This will not indent inner map entries for inner maps with BTF info,
will it? But I guess indenting them would require changing the JSON
writer, probably not worth it. It's probably OK if we have blank lines
to delimit the different maps in that case.

Acked-by: Quentin Monnet <qmo@kernel.org>

Thank you!

The series will need to be rebased once the batch lookups are merged, so
that it can go through CI.

  reply	other threads:[~2026-11-11 16:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  7:19 [PATCH bpf-next v12 0/3] bpftool: Add recursive map dumping Tianyi Chen
2026-11-11  7:19 ` [PATCH bpf-next v12 1/3] bpftool: Reset map info before each query in show and dump loops Tianyi Chen
2026-11-11  7:19 ` [PATCH bpf-next v12 2/3] bpftool: Add recursive map dumping Tianyi Chen
2026-11-11 16:24   ` Quentin Monnet [this message]
2026-11-11  7:19 ` [PATCH bpf-next v12 3/3] selftests/bpf: Cover recursive bpftool map dumps Tianyi Chen
2026-11-11 16:24   ` Quentin Monnet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=447aeaaa-dd74-47c2-b517-790ae98e8962@kernel.org \
    --to=qmo@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=hi@tychen.cc \
    --cc=ihor.solodrai@linux.dev \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=memxor@gmail.com \
    --cc=shuah@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox