Skip to contentSkip to conversation

bpftool: Show map IDs along with struct_ops links.

PATCH Superseded Kui-Feng Lee 4 participants 5 messages Apr 19, 2023 – Apr 21, 2023

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bpftool: Show map IDs along with struct_ops links.

A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach struct_ops to links. (226bc6ae6405) It would be helpful for users to know which map is associated with the link.

The assumption was that every link is associated with a BPF program, but this does not hold true for struct_ops. It would be better to display map_id instead of prog_id for struct_ops links. However, some tools may rely on the old assumption and need a prog_id. The discussion on the mailing list suggests that tools should parse JSON format. We will maintain the existing JSON format by adding a map_id without removing prog_id. As for plain text format, we will remove prog_id from the header line and add a map_id for struct_ops links.

---
 tools/bpf/bpftool/link.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/bpf/bpftool/link.c +8 -1
index f985b79cca27..8eb8520bd7b4 100644
@@ -195,6 +195,10 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
 				 info->netns.netns_ino);
 		show_link_attach_type_json(info->netns.attach_type, json_wtr);
 		break;
+	case BPF_LINK_TYPE_STRUCT_OPS:
+		jsonw_uint_field(json_wtr, "map_id",
+				 info->struct_ops.map_id);
+		break;
 	default:
 		break;
 	}
@@ -227,7 +231,10 @@ static void show_link_header_plain(struct bpf_link_info *info)
 	else
 		printf("type %u  ", info->type);
 
-	printf("prog %u  ", info->prog_id);
+	if (info->type == BPF_LINK_TYPE_STRUCT_OPS)
+		printf("map_id %u  ", info->struct_ops.map_id);
+	else
+		printf("prog %u  ", info->prog_id);
 }
 
 static void show_link_attach_type_plain(__u32 attach_type)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 14 lines · Kui-Feng Lee

A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach struct_ops to links. (226bc6ae6405) It would be helpful for users to know which map is associated with the link.

The assumption was that every link is associated with a BPF program, but this does not hold true for struct_ops. It would be better to display map_id instead of prog_id for struct_ops links. However, some tools may rely on the old assumption and need a prog_id. The discussion on the mailing list suggests that tools should parse JSON format. We will maintain the existing JSON format by adding a map_id without removing prog_id. As for plain text format, we will remove prog_id from the header line and add a map_id for struct_ops links.

Quoted 2 lines

Looks all good from my side, thank you.

#2 lore raw

Thank you for reviewing this.

Quoted 19 lines · Quentin Monnet
Quoted 14 lines · Kui-Feng Lee

A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach struct_ops to links. (226bc6ae6405) It would be helpful for users to know which map is associated with the link.

The assumption was that every link is associated with a BPF program, but this does not hold true for struct_ops. It would be better to display map_id instead of prog_id for struct_ops links. However, some tools may rely on the old assumption and need a prog_id. The discussion on the mailing list suggests that tools should parse JSON format. We will maintain the existing JSON format by adding a map_id without removing prog_id. As for plain text format, we will remove prog_id from the header line and add a map_id for struct_ops links.

Quoted 2 lines

Looks all good from my side, thank you.

#3 lore raw
In reply to Kui-Feng Lee
Quoted 36 lines · Kui-Feng Lee

A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach struct_ops to links. (226bc6ae6405) It would be helpful for users to know which map is associated with the link.

The assumption was that every link is associated with a BPF program, but this does not hold true for struct_ops. It would be better to display map_id instead of prog_id for struct_ops links. However, some tools may rely on the old assumption and need a prog_id. The discussion on the mailing list suggests that tools should parse JSON format. We will maintain the existing JSON format by adding a map_id without removing prog_id. As for plain text format, we will remove prog_id from the header line and add a map_id for struct_ops links.

---
 tools/bpf/bpftool/link.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/bpf/bpftool/link.c +4 -0
index f985b79cca27..8eb8520bd7b4 100644
@@ -195,6 +195,10 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
                                 info->netns.netns_ino);
                show_link_attach_type_json(info->netns.attach_type, json_wtr);
                break;
+       case BPF_LINK_TYPE_STRUCT_OPS:
+               jsonw_uint_field(json_wtr, "map_id",
+                                info->struct_ops.map_id);
+               break;
        default:
                break;
        }

tools/bpf/bpftool/link.c static void show_link_header_plain(struct bpf_link_info *info) · line 237

Quoted 8 lines
tools/bpf/bpftool/link.c +4 -1
@@ -227,7 +231,10 @@ static void show_link_header_plain(struct bpf_link_info *info)
        else
                printf("type %u  ", info->type);
 
-       printf("prog %u  ", info->prog_id);
+       if (info->type == BPF_LINK_TYPE_STRUCT_OPS)
+               printf("map_id %u  ", info->struct_ops.map_id);
+       else
+               printf("prog %u  ", info->prog_id);

if we output "prog %u" for prog_id, shouldn't we just output "map %u" for map_id?

Quoted 6 lines
tools/bpf/bpftool/link.c +0 -1
 }
 
 static void show_link_attach_type_plain(__u32 attach_type)
--

2.34.1

#4 lore raw
Quoted 40 lines · Andrii Nakryiko
Quoted 39 lines · Kui-Feng Lee

A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach struct_ops to links. (226bc6ae6405) It would be helpful for users to know which map is associated with the link.

The assumption was that every link is associated with a BPF program, but this does not hold true for struct_ops. It would be better to display map_id instead of prog_id for struct_ops links. However, some tools may rely on the old assumption and need a prog_id. The discussion on the mailing list suggests that tools should parse JSON format. We will maintain the existing JSON format by adding a map_id without removing prog_id. As for plain text format, we will remove prog_id from the header line and add a map_id for struct_ops links.

---
  tools/bpf/bpftool/link.c | 9 ++++++++-
  1 file changed, 8 insertions(+), 1 deletion(-)
tools/bpf/bpftool/link.c +4 -0
index f985b79cca27..8eb8520bd7b4 100644
@@ -195,6 +195,10 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
                                  info->netns.netns_ino);
                 show_link_attach_type_json(info->netns.attach_type, json_wtr);
                 break;
+       case BPF_LINK_TYPE_STRUCT_OPS:
+               jsonw_uint_field(json_wtr, "map_id",
+                                info->struct_ops.map_id);
+               break;
         default:
                 break;
         }
@@ -227,7 +231,10 @@ static void show_link_header_plain(struct bpf_link_info *info)
         else
                 printf("type %u  ", info->type);
 
Quoted 8 lines

tools/bpf/bpftool/link.c static void show_link_header_plain(struct bpf_link_info *info) · line 237

Quoted 5 lines
tools/bpf/bpftool/link.c +4 -1
-       printf("prog %u  ", info->prog_id);
+       if (info->type == BPF_LINK_TYPE_STRUCT_OPS)
+               printf("map_id %u  ", info->struct_ops.map_id);
+       else
+               printf("prog %u  ", info->prog_id);

if we output "prog %u" for prog_id, shouldn't we just output "map %u" for map_id?

"map" make sense to me.

Quoted 7 lines
Quoted 7 lines
tools/bpf/bpftool/link.c +0 -1
  }
 
  static void show_link_attach_type_plain(__u32 attach_type)
--

2.34.1