tools: bpftool: optionally show filenames of pinned objects

Making it optional to show file names of pinned objects because
it scans complete bpf-fs filesystem which is costly.
Added option -f|--bpffs. Documentation updated.

Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Prashant Bhole 2017-11-08 13:55:49 +09:00 committed by David S. Miller
parent 4990f1f461
commit c541b73466
6 changed files with 25 additions and 8 deletions

View File

@ -12,7 +12,7 @@ SYNOPSIS
**bpftool** [*OPTIONS*] **map** *COMMAND* **bpftool** [*OPTIONS*] **map** *COMMAND*
*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] } *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
*COMMANDS* := *COMMANDS* :=
{ **show** | **dump** | **update** | **lookup** | **getnext** | **delete** { **show** | **dump** | **update** | **lookup** | **getnext** | **delete**
@ -86,6 +86,9 @@ OPTIONS
-p, --pretty -p, --pretty
Generate human-readable JSON output. Implies **-j**. Generate human-readable JSON output. Implies **-j**.
-f, --bpffs
Show file names of pinned maps.
EXAMPLES EXAMPLES
======== ========
**# bpftool map show** **# bpftool map show**

View File

@ -12,7 +12,7 @@ SYNOPSIS
**bpftool** [*OPTIONS*] **prog** *COMMAND* **bpftool** [*OPTIONS*] **prog** *COMMAND*
*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] } *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
*COMMANDS* := *COMMANDS* :=
{ **show** | **dump xlated** | **dump jited** | **pin** | **help** } { **show** | **dump xlated** | **dump jited** | **pin** | **help** }
@ -75,6 +75,9 @@ OPTIONS
-p, --pretty -p, --pretty
Generate human-readable JSON output. Implies **-j**. Generate human-readable JSON output. Implies **-j**.
-f, --bpffs
Show file names of pinned programs.
EXAMPLES EXAMPLES
======== ========
**# bpftool prog show** **# bpftool prog show**

View File

@ -54,6 +54,7 @@ static int (*last_do_help)(int argc, char **argv);
json_writer_t *json_wtr; json_writer_t *json_wtr;
bool pretty_output; bool pretty_output;
bool json_output; bool json_output;
bool show_pinned;
struct pinned_obj_table prog_table; struct pinned_obj_table prog_table;
struct pinned_obj_table map_table; struct pinned_obj_table map_table;
@ -265,6 +266,7 @@ int main(int argc, char **argv)
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "pretty", no_argument, NULL, 'p' }, { "pretty", no_argument, NULL, 'p' },
{ "version", no_argument, NULL, 'V' }, { "version", no_argument, NULL, 'V' },
{ "bpffs", no_argument, NULL, 'f' },
{ 0 } { 0 }
}; };
int opt, ret; int opt, ret;
@ -272,12 +274,13 @@ int main(int argc, char **argv)
last_do_help = do_help; last_do_help = do_help;
pretty_output = false; pretty_output = false;
json_output = false; json_output = false;
show_pinned = false;
bin_name = argv[0]; bin_name = argv[0];
hash_init(prog_table.table); hash_init(prog_table.table);
hash_init(map_table.table); hash_init(map_table.table);
while ((opt = getopt_long(argc, argv, "Vhpj", while ((opt = getopt_long(argc, argv, "Vhpjf",
options, NULL)) >= 0) { options, NULL)) >= 0) {
switch (opt) { switch (opt) {
case 'V': case 'V':
@ -290,6 +293,9 @@ int main(int argc, char **argv)
case 'j': case 'j':
json_output = true; json_output = true;
break; break;
case 'f':
show_pinned = true;
break;
default: default:
usage(); usage();
} }
@ -316,8 +322,10 @@ int main(int argc, char **argv)
if (json_output) if (json_output)
jsonw_destroy(&json_wtr); jsonw_destroy(&json_wtr);
if (show_pinned) {
delete_pinned_obj_table(&prog_table); delete_pinned_obj_table(&prog_table);
delete_pinned_obj_table(&map_table); delete_pinned_obj_table(&map_table);
}
return ret; return ret;
} }

View File

@ -59,7 +59,7 @@
#define HELP_SPEC_PROGRAM \ #define HELP_SPEC_PROGRAM \
"PROG := { id PROG_ID | pinned FILE | tag PROG_TAG }" "PROG := { id PROG_ID | pinned FILE | tag PROG_TAG }"
#define HELP_SPEC_OPTIONS \ #define HELP_SPEC_OPTIONS \
"OPTIONS := { {-j|--json} [{-p|--pretty}] }" "OPTIONS := { {-j|--json} [{-p|--pretty}] | {-f|--bpffs} }"
enum bpf_obj_type { enum bpf_obj_type {
BPF_OBJ_UNKNOWN, BPF_OBJ_UNKNOWN,
@ -71,6 +71,7 @@ extern const char *bin_name;
extern json_writer_t *json_wtr; extern json_writer_t *json_wtr;
extern bool json_output; extern bool json_output;
extern bool show_pinned;
extern struct pinned_obj_table prog_table; extern struct pinned_obj_table prog_table;
extern struct pinned_obj_table map_table; extern struct pinned_obj_table map_table;

View File

@ -497,6 +497,7 @@ static int do_show(int argc, char **argv)
int err; int err;
int fd; int fd;
if (show_pinned)
build_pinned_obj_table(&map_table, BPF_OBJ_MAP); build_pinned_obj_table(&map_table, BPF_OBJ_MAP);
if (argc == 2) { if (argc == 2) {

View File

@ -382,6 +382,7 @@ static int do_show(int argc, char **argv)
int err; int err;
int fd; int fd;
if (show_pinned)
build_pinned_obj_table(&prog_table, BPF_OBJ_PROG); build_pinned_obj_table(&prog_table, BPF_OBJ_PROG);
if (argc == 2) { if (argc == 2) {