netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
To: "David S . Miller" <davem@davemloft.net>
Cc: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>,
	netdev@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Quentin Monnet <quentin.monnet@netronome.com>,
	Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: [PATCH net-next 3/3] tools: bpftool: optionally show filenames of pinned objects
Date: Tue, 31 Oct 2017 16:36:32 +0900	[thread overview]
Message-ID: <20171031073632.8140-4-bhole_prashant_q7@lab.ntt.co.jp> (raw)
In-Reply-To: <20171031073632.8140-1-bhole_prashant_q7@lab.ntt.co.jp>

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

Signed-off-by: Prashant Bhole <bhole_prashant_q7@lab.ntt.co.jp>
---
 tools/bpf/bpftool/main.c | 14 +++++++++++---
 tools/bpf/bpftool/main.h |  3 ++-
 tools/bpf/bpftool/map.c  |  3 ++-
 tools/bpf/bpftool/prog.c |  3 ++-
 4 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 6ad53f1..2ae26c6 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -54,6 +54,7 @@
 json_writer_t *json_wtr;
 bool pretty_output;
 bool json_output;
+bool show_pinned;
 struct pinned_obj_table prog_table;
 struct pinned_obj_table map_table;
 
@@ -265,6 +266,7 @@ int main(int argc, char **argv)
 		{ "help",	no_argument,	NULL,	'h' },
 		{ "pretty",	no_argument,	NULL,	'p' },
 		{ "version",	no_argument,	NULL,	'V' },
+		{ "pinned",	no_argument,	NULL,	'l' },
 		{ 0 }
 	};
 	int opt, ret;
@@ -272,12 +274,13 @@ int main(int argc, char **argv)
 	last_do_help = do_help;
 	pretty_output = false;
 	json_output = false;
+	show_pinned = false;
 	bin_name = argv[0];
 
 	hash_init(prog_table.table);
 	hash_init(map_table.table);
 
-	while ((opt = getopt_long(argc, argv, "Vhpj",
+	while ((opt = getopt_long(argc, argv, "Vhpjl",
 				  options, NULL)) >= 0) {
 		switch (opt) {
 		case 'V':
@@ -290,6 +293,9 @@ int main(int argc, char **argv)
 		case 'j':
 			json_output = true;
 			break;
+		case 'l':
+			show_pinned = true;
+			break;
 		default:
 			usage();
 		}
@@ -316,8 +322,10 @@ int main(int argc, char **argv)
 	if (json_output)
 		jsonw_destroy(&json_wtr);
 
-	delete_pinned_obj_table(&prog_table);
-	delete_pinned_obj_table(&map_table);
+	if (show_pinned) {
+		delete_pinned_obj_table(&prog_table);
+		delete_pinned_obj_table(&map_table);
+	}
 
 	return ret;
 }
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index 3abaa17..6c668a6 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -59,7 +59,7 @@
 #define HELP_SPEC_PROGRAM						\
 	"PROG := { id PROG_ID | pinned FILE | tag PROG_TAG }"
 #define HELP_SPEC_OPTIONS						\
-	"OPTIONS := { {-j|--json} [{-p|--pretty}] }"
+	"OPTIONS := { {-j|--json} [{-p|--pretty}] {-l |--pinned} }"
 
 enum bpf_obj_type {
 	BPF_OBJ_UNKNOWN,
@@ -71,6 +71,7 @@ enum bpf_obj_type {
 
 extern json_writer_t *json_wtr;
 extern bool json_output;
+extern bool show_pinned;
 extern struct pinned_obj_table prog_table;
 extern struct pinned_obj_table map_table;
 
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index fbe236e..c4354f8 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -496,7 +496,8 @@ static int do_show(int argc, char **argv)
 	int err;
 	int fd;
 
-	build_pinned_obj_table(&map_table, BPF_OBJ_MAP);
+	if (show_pinned)
+		build_pinned_obj_table(&map_table, BPF_OBJ_MAP);
 
 	if (argc == 2) {
 		fd = map_parse_fd_and_info(&argc, &argv, &info, &len);
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index cd29eae..c97c954 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -350,7 +350,8 @@ static int do_show(int argc, char **argv)
 	int err;
 	int fd;
 
-	build_pinned_obj_table(&prog_table, BPF_OBJ_PROG);
+	if (show_pinned)
+		build_pinned_obj_table(&prog_table, BPF_OBJ_PROG);
 
 	if (argc == 2) {
 		fd = prog_parse_fd(&argc, &argv);
-- 
1.8.3.1

  parent reply	other threads:[~2017-10-31  8:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-31  7:36 [PATCH net-next 0/3] tools: bpftool: show filenames of pinned objects Prashant Bhole
2017-10-31  7:36 ` [PATCH net-next 1/3] tools: bpftool: open pinned object without type check Prashant Bhole
2017-10-31  7:36 ` [PATCH net-next 2/3] tools: bpftool: show filenames of pinned objects Prashant Bhole
2017-10-31 11:41   ` Quentin Monnet
2017-10-31 17:35     ` Jakub Kicinski
2017-11-02  7:57     ` Prashant Bhole
2017-10-31  7:36 ` Prashant Bhole [this message]
2017-10-31 11:54   ` [PATCH net-next 3/3] tools: bpftool: optionally " Quentin Monnet
2017-10-31 17:37     ` Jakub Kicinski

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=20171031073632.8140-4-bhole_prashant_q7@lab.ntt.co.jp \
    --to=bhole_prashant_q7@lab.ntt.co.jp \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=jakub.kicinski@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=quentin.monnet@netronome.com \
    /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;
as well as URLs for NNTP newsgroup(s).