Skip to content

Commit c354ff2

Browse files
qmonnetborkmann
authored andcommitted
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: Quentin Monnet <quentin.monnet@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 1f8919b commit c354ff2

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

‎tools/bpf/bpftool/map.c‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,11 @@ static int parse_elem(char **argv, struct bpf_map_info *info,
481481

482482
static int show_map_close_json(int fd, struct bpf_map_info *info)
483483
{
484-
char *memlock;
484+
char *memlock, *frozen_str;
485+
int frozen = 0;
485486

486487
memlock = get_fdinfo(fd, "memlock");
488+
frozen_str = get_fdinfo(fd, "frozen");
487489

488490
jsonw_start_object(json_wtr);
489491

@@ -533,6 +535,12 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
533535
}
534536
close(fd);
535537

538+
if (frozen_str) {
539+
frozen = atoi(frozen_str);
540+
free(frozen_str);
541+
}
542+
jsonw_int_field(json_wtr, "frozen", frozen);
543+
536544
if (info->btf_id)
537545
jsonw_int_field(json_wtr, "btf_id", info->btf_id);
538546

@@ -555,9 +563,11 @@ static int show_map_close_json(int fd, struct bpf_map_info *info)
555563

556564
static int show_map_close_plain(int fd, struct bpf_map_info *info)
557565
{
558-
char *memlock;
566+
char *memlock, *frozen_str;
567+
int frozen = 0;
559568

560569
memlock = get_fdinfo(fd, "memlock");
570+
frozen_str = get_fdinfo(fd, "frozen");
561571

562572
printf("%u: ", info->id);
563573
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)
610620
printf("\n\tpinned %s", obj->path);
611621
}
612622
}
623+
printf("\n");
624+
625+
if (frozen_str) {
626+
frozen = atoi(frozen_str);
627+
free(frozen_str);
628+
}
629+
630+
if (!info->btf_id && !frozen)
631+
return 0;
632+
633+
printf("\t");
613634

614635
if (info->btf_id)
615-
printf("\n\tbtf_id %d", info->btf_id);
636+
printf("btf_id %d", info->btf_id);
637+
638+
if (frozen)
639+
printf("%sfrozen", info->btf_id ? " " : "");
616640

617641
printf("\n");
618642
return 0;

0 commit comments

Comments
 (0)