提交 c354ff2e 编写于 作者: Q Quentin Monnet 提交者: Daniel Borkmann

tools: bpftool: show frozen status for maps

When listing maps, read their "frozen" status from procfs, and tell if
maps are frozen.

As commit log for map freezing command mentions that the feature might
be extended with flags (e.g. for write-only instead of read-only) in the
future, use an integer and not a boolean for JSON output.
Signed-off-by: NQuentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: NJakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
上级 1f8919b1
...@@ -481,9 +481,11 @@ static int parse_elem(char **argv, struct bpf_map_info *info, ...@@ -481,9 +481,11 @@ static int parse_elem(char **argv, struct bpf_map_info *info,
static int show_map_close_json(int fd, struct bpf_map_info *info) static int show_map_close_json(int fd, struct bpf_map_info *info)
{ {
char *memlock; char *memlock, *frozen_str;
int frozen = 0;
memlock = get_fdinfo(fd, "memlock"); memlock = get_fdinfo(fd, "memlock");
frozen_str = get_fdinfo(fd, "frozen");
jsonw_start_object(json_wtr); jsonw_start_object(json_wtr);
...@@ -533,6 +535,12 @@ static int show_map_close_json(int fd, struct bpf_map_info *info) ...@@ -533,6 +535,12 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
} }
close(fd); close(fd);
if (frozen_str) {
frozen = atoi(frozen_str);
free(frozen_str);
}
jsonw_int_field(json_wtr, "frozen", frozen);
if (info->btf_id) if (info->btf_id)
jsonw_int_field(json_wtr, "btf_id", info->btf_id); jsonw_int_field(json_wtr, "btf_id", info->btf_id);
...@@ -555,9 +563,11 @@ static int show_map_close_json(int fd, struct bpf_map_info *info) ...@@ -555,9 +563,11 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
static int show_map_close_plain(int fd, struct bpf_map_info *info) static int show_map_close_plain(int fd, struct bpf_map_info *info)
{ {
char *memlock; char *memlock, *frozen_str;
int frozen = 0;
memlock = get_fdinfo(fd, "memlock"); memlock = get_fdinfo(fd, "memlock");
frozen_str = get_fdinfo(fd, "frozen");
printf("%u: ", info->id); printf("%u: ", info->id);
if (info->type < ARRAY_SIZE(map_type_name)) if (info->type < ARRAY_SIZE(map_type_name))
...@@ -610,9 +620,23 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info) ...@@ -610,9 +620,23 @@ static int show_map_close_plain(int fd, struct bpf_map_info *info)
printf("\n\tpinned %s", obj->path); printf("\n\tpinned %s", obj->path);
} }
} }
printf("\n");
if (frozen_str) {
frozen = atoi(frozen_str);
free(frozen_str);
}
if (!info->btf_id && !frozen)
return 0;
printf("\t");
if (info->btf_id) if (info->btf_id)
printf("\n\tbtf_id %d", info->btf_id); printf("btf_id %d", info->btf_id);
if (frozen)
printf("%sfrozen", info->btf_id ? " " : "");
printf("\n"); printf("\n");
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册