BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next v3] bpftool: Show map IDs along with struct_ops links.
@ 2023-04-21 18:17 Kui-Feng Lee
  2023-04-21 21:42 ` Kui-Feng Lee
  0 siblings, 1 reply; 2+ messages in thread
From: Kui-Feng Lee @ 2023-04-21 18:17 UTC (permalink / raw)
  To: bpf, ast, martin.lau, yhs, song, kernel-team, andrii
  Cc: Kui-Feng Lee, Quentin Monnet

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.

Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
---
 tools/bpf/bpftool/link.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index f985b79cca27..c79f2e8927d6 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -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 %u  ", info->struct_ops.map_id);
+	else
+		printf("prog %u  ", info->prog_id);
 }
 
 static void show_link_attach_type_plain(__u32 attach_type)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next v3] bpftool: Show map IDs along with struct_ops links.
  2023-04-21 18:17 [PATCH bpf-next v3] bpftool: Show map IDs along with struct_ops links Kui-Feng Lee
@ 2023-04-21 21:42 ` Kui-Feng Lee
  0 siblings, 0 replies; 2+ messages in thread
From: Kui-Feng Lee @ 2023-04-21 21:42 UTC (permalink / raw)
  To: Kui-Feng Lee, bpf, ast, martin.lau, yhs, song, kernel-team,
	andrii
  Cc: Kui-Feng Lee, Quentin Monnet

Due to a confliction, I have rebased this patch and sent v4.

On 4/21/23 11:17, Kui-Feng Lee wrote:
> 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.
> 
> Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
> Reviewed-by: Quentin Monnet <quentin@isovalent.com>
> ---
>   tools/bpf/bpftool/link.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
> index f985b79cca27..c79f2e8927d6 100644
> --- a/tools/bpf/bpftool/link.c
> +++ b/tools/bpf/bpftool/link.c
> @@ -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 %u  ", info->struct_ops.map_id);
> +	else
> +		printf("prog %u  ", info->prog_id);
>   }
>   
>   static void show_link_attach_type_plain(__u32 attach_type)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-21 21:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-21 18:17 [PATCH bpf-next v3] bpftool: Show map IDs along with struct_ops links Kui-Feng Lee
2023-04-21 21:42 ` Kui-Feng Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox