diff mbox series

[bpf-next] bpftool: add current libbpf_strict mode to version output

Message ID 20211112164432.3138956-1-sdf@google.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series [bpf-next] bpftool: add current libbpf_strict mode to version output | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 5 maintainers not CCed: yhs@fb.com john.fastabend@gmail.com kafai@fb.com songliubraving@fb.com kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next fail VM_Test
bpf/vmtest-bpf-next-PR fail PR summary

Commit Message

Stanislav Fomichev Nov. 12, 2021, 4:44 p.m. UTC
+ bpftool --legacy version
bpftool v5.15.0
features: libbfd, skeletons
+ bpftool version
bpftool v5.15.0
features: libbfd, libbpf_strict, skeletons
+ bpftool --json --legacy version
{"version":"5.15.0","features":{"libbfd":true,"libbpf_strict":false,"skeletons":true}}
+ bpftool --json version
{"version":"5.15.0","features":{"libbfd":true,"libbpf_strict":true,"skeletons":true}}

Suggested-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/bpf/bpftool/main.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Quentin Monnet Nov. 12, 2021, 5:02 p.m. UTC | #1
2021-11-12 08:44 UTC-0800 ~ Stanislav Fomichev <sdf@google.com>
> + bpftool --legacy version
> bpftool v5.15.0
> features: libbfd, skeletons
> + bpftool version
> bpftool v5.15.0
> features: libbfd, libbpf_strict, skeletons
> + bpftool --json --legacy version
> {"version":"5.15.0","features":{"libbfd":true,"libbpf_strict":false,"skeletons":true}}
> + bpftool --json version
> {"version":"5.15.0","features":{"libbfd":true,"libbpf_strict":true,"skeletons":true}}

Nice, thanks!
The following doesn't work as expected, though:

    $ ./bpftool --version --legacy
    ./bpftool v5.15.0
    features: libbfd, libbpf_strict, skeletons

This is because we run do_version() immediately when parsing --version,
and we don't parse --legacy in that case. Could we postpone do_version()
until after we have parsed all options, so that the output from the
above is consistent with e.g. "bpftool --legacy --version"?

Thanks,
Quentin
Stanislav Fomichev Nov. 12, 2021, 5:04 p.m. UTC | #2
On Fri, Nov 12, 2021 at 9:02 AM Quentin Monnet <quentin@isovalent.com> wrote:
>
> 2021-11-12 08:44 UTC-0800 ~ Stanislav Fomichev <sdf@google.com>
> > + bpftool --legacy version
> > bpftool v5.15.0
> > features: libbfd, skeletons
> > + bpftool version
> > bpftool v5.15.0
> > features: libbfd, libbpf_strict, skeletons
> > + bpftool --json --legacy version
> > {"version":"5.15.0","features":{"libbfd":true,"libbpf_strict":false,"skeletons":true}}
> > + bpftool --json version
> > {"version":"5.15.0","features":{"libbfd":true,"libbpf_strict":true,"skeletons":true}}
>
> Nice, thanks!
> The following doesn't work as expected, though:
>
>     $ ./bpftool --version --legacy
>     ./bpftool v5.15.0
>     features: libbfd, libbpf_strict, skeletons
>
> This is because we run do_version() immediately when parsing --version,
> and we don't parse --legacy in that case. Could we postpone do_version()
> until after we have parsed all options, so that the output from the
> above is consistent with e.g. "bpftool --legacy --version"?

Oh, good find! Let me move some code around to fix that.
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 473791e87f7d..edbb146287ee 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -93,6 +93,7 @@  static int do_version(int argc, char **argv)
 		jsonw_name(json_wtr, "features");
 		jsonw_start_object(json_wtr);	/* features */
 		jsonw_bool_field(json_wtr, "libbfd", has_libbfd);
+		jsonw_bool_field(json_wtr, "libbpf_strict", !legacy_libbpf);
 		jsonw_bool_field(json_wtr, "skeletons", has_skeletons);
 		jsonw_end_object(json_wtr);	/* features */
 
@@ -106,6 +107,10 @@  static int do_version(int argc, char **argv)
 			printf(" libbfd");
 			nb_features++;
 		}
+		if (!legacy_libbpf) {
+			printf("%s libbpf_strict", nb_features++ ? "," : "");
+			nb_features++;
+		}
 		if (has_skeletons)
 			printf("%s skeletons", nb_features++ ? "," : "");
 		printf("\n");