From: Quentin Monnet <qmo@kernel.org>
To: Tianyi Chen <hi@tychen.cc>, bpf@vger.kernel.org
Cc: andrii@kernel.org, eddyz87@gmail.com, ihor.solodrai@linux.dev,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf-next v7 1/2] bpftool: Add recursive map dumping
Date: Fri, 25 Sep 2026 12:26:38 +0100 [thread overview]
Message-ID: <6ed88738-4e3b-407c-90c2-bf7717f3e653@kernel.org> (raw)
In-Reply-To: <20260924161434.95116-2-hi@tychen.cc>
2026-09-25 01:14 UTC+0900 ~ Tianyi Chen <hi@tychen.cc>
> Dumping a map-of-maps currently shows inner map IDs without their
> contents. Add a recursive keyword to map dump to include referenced
> inner maps, leaving the default output unchanged. Show selected maps
> followed by distinct inner maps, preserving plain and BTF formatting
> and using an array of map objects for JSON output.
>
> Holding every discovered inner-map FD open would make descriptor use
> grow with the number of maps and could exhaust RLIMIT_NOFILE. Keep the
> selected map FDs open, queue distinct inner map IDs, and open, dump and
> close each queued map in turn. This needs only one additional map FD.
> The tradeoff is deferred ID resolution: concurrently removed inner
> maps can disappear before they are opened, so the dump is not atomic.
>
> Report failure when an inner map cannot be opened, retain per-entry
> lookup errors, and close JSON containers before returning.
>
> Link: https://github.com/libbpf/bpftool/issues/58
> Assisted-by: LLM
> Signed-off-by: Tianyi Chen <hi@tychen.cc>
> ---
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index 20d59eab09a1..ef47de7da200 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -907,21 +960,37 @@ map_dump(int fd, struct bpf_map_info *info, json_writer_t *wtr,
> free(value);
> free(cpu_ids);
> free_map_kv_btf(btf);
> + if (plain_btf_wtr)
> + jsonw_destroy(&plain_btf_wtr);
>
> return err;
> }
>
> static int do_dump(int argc, char **argv)
> {
> + LIBBPF_OPTS(bpf_get_fd_by_id_opts, opts,
> + .open_flags = BPF_F_RDONLY,
> + );
> json_writer_t *wtr = NULL, *btf_wtr = NULL;
> struct bpf_map_info info = {};
> + struct map_dump_ctx ctx = {};
> + bool recursive_dump = false;
> int nb_fds, i = 0;
> __u32 len = sizeof(info);
> int *fds = NULL;
> int err = -1;
> + size_t j;
>
> - if (argc != 2)
> + if (argc != 2 && argc != 3)
> usage();
> + if (argc == 3) {
> + if (!*argv[2] || !is_prefix(argv[2], "recursive")) {
> + p_err("expected 'recursive', got: '%s'", argv[2]);
> + return -1;
> + }
> + recursive_dump = true;
> + argc--;
> + }
If we put the keyword first, we'll get a confusing message:
# bpftool map dump recursive id 1337
Error: expected 'recursive', got: '1337'
Can we align it with what most other subcommands in bpftool do, please?
if (!REQ_ARGS(2))
return -1;
fds = malloc(sizeof(int));
if (!fds) {
p_err("mem alloc failed");
return -1;
}
nb_fds = map_parse_fds(&argc, &argv, &fds, BPF_F_RDONLY);
if (nb_fds < 1)
goto exit_free;
while (argc > 0) {
if (is_prefix(*argv, "recursive")) {
NEXT_ARG();
recursive_dump = true;
} else {
p_err("expected 'recursive', got: '%s'", *argv);
goto exit_free;
}
}
The rest looks good, thank you.
Quentin
next prev parent reply other threads:[~2026-09-25 11:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 16:14 [PATCH bpf-next v7 0/2] bpftool: Add recursive map dumping Tianyi Chen
2026-09-24 16:14 ` [PATCH bpf-next v7 1/2] " Tianyi Chen
2026-09-25 11:26 ` Quentin Monnet [this message]
2026-09-25 17:46 ` Tianyi Chen
2026-09-24 16:14 ` [PATCH bpf-next v7 2/2] selftests/bpf: Cover recursive bpftool map dumps Tianyi Chen
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=6ed88738-4e3b-407c-90c2-bf7717f3e653@kernel.org \
--to=qmo@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=eddyz87@gmail.com \
--cc=hi@tychen.cc \
--cc=ihor.solodrai@linux.dev \
--cc=linux-kselftest@vger.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