Thread (24 messages) 24 messages, 3 authors, 2022-01-21

Re: [PATCH bpf-next v4 3/8] bpftool: Add gen btf command

flat view

From: Andrii Nakryiko <hidden>
Date: 2022-01-15 02:09:51
Also in: bpf

On Wed, Jan 12, 2022 at 6:27 AM Mauricio Vásquez [off-list ref] wrote:
This command is implemented under the "gen" command in bpftool and the
syntax is the following:

$ bpftool gen btf INPUT OUTPUT OBJECT(S)
"gen btf" doesn't really convey that it's a minimized BTF for CO-RE,
maybe let's do something more verbose but also more precise, it's not
like this is going to be used by everyone multiple times a day, so
verboseness is not a bad thing here. Naming is hard, but something
like `bpftool gen min_core_btf` probably would give a bit better
pointer as to what this command is doing (minimal CO-RE BTF, right?)
INPUT can be either a single BTF file or a folder containing BTF files,
when it's a folder, a BTF file is generated for each BTF file contained
in this folder. OUTPUT is the file (or folder) where generated files are
stored and OBJECT(S) is the list of bpf objects we want to generate the
BTF file(s) for (each generated BTF file contains all the types needed
by all the objects).

Signed-off-by: Mauricio Vásquez <redacted>
Signed-off-by: Rafael David Tinoco <redacted>
Signed-off-by: Lorenzo Fontana <redacted>
Signed-off-by: Leonardo Di Donato <redacted>
---
 tools/bpf/bpftool/gen.c | 117 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 117 insertions(+)
[...]
quoted hunk ↗ jump to hunk
+
+       while ((dir = readdir(d)) != NULL) {
+               if (dir->d_type != DT_REG)
+                       continue;
+
+               if (strncmp(dir->d_name + strlen(dir->d_name) - 4, ".btf", 4))
+                       continue;
+
+               snprintf(src_btf_path, sizeof(src_btf_path), "%s/%s", input, dir->d_name);
+               snprintf(dst_btf_path, sizeof(dst_btf_path), "%s/%s", output, dir->d_name);
+
+               printf("SBTF: %s\n", src_btf_path);
What's SBTF? Is this part of bpftool "protocol" now? It should be
something a bit more meaningful...
quoted hunk ↗ jump to hunk
+
+               err = btfgen(src_btf_path, dst_btf_path, objs);
+               if (err)
+                       goto out;
+       }
+
+out:
+       if (!err)
+               printf("STAT: done!\n");
similar, STAT? what's that? Do we need "done!" message in tool's output?
+       free(objs);
+       closedir(d);
+       return err;
+}
+
 static const struct cmd cmds[] = {
        { "object",     do_object },
        { "skeleton",   do_skeleton },
+       { "btf",        do_gen_btf},
        { "help",       do_help },
        { 0 }
 };
--
2.25.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help