devlink: add per-port resource support
Subsystems (5)
cover devlink: add per-port resource support
Hi,
Currently, devlink resource show only supports querying a specific device and displays device-level resources. However, some resources are per-port, such as the maximum number of SFs that can be created on a specific PF port.
This series extends devlink resource show with full support for port-level resources, including a dump mode, per-port querying syntax, and scope filtering. In preparation for these features, the first two patches refactor how dpipe tables are handled to unblock dump support and ensure errors in secondary queries are non-fatal.
The series is organized as follows:
Patch 1 splits the dpipe tables display into a separate function.
Patch 2 moves the dpipe tables query into the per-device resource show callback, ensuring it behaves correctly during a multi-device dump.
Patch 3 fixes a pre-existing memory leak in resource_ctx_fini.
Patch 4 adds dump support to resource show (no device required).
Patch 5 shows port-level resources returned in a dump reply.
Patch 6 adds DEV/PORT_INDEX syntax to resource show.
Patch 7 adds scope filter to resource show.
With this series, users can query resources at all levels:
$ devlink resource show pci/0000:03:00.0: name local_max_SFs size 508 unit entry name external_max_SFs size 508 unit entry pci/0000:03:00.0/196608: name max_SFs size 20 unit entry
$ devlink resource show scope dev pci/0000:03:00.0: name local_max_SFs size 508 unit entry name external_max_SFs size 508 unit entry
$ devlink resource show scope port pci/0000:03:00.0/196608: name max_SFs size 20 unit entry
$ devlink resource show pci/0000:03:00.0/196608 pci/0000:03:00.0/196608: name max_SFs size 20 unit entry
This series is the userspace counterpart to the kernel series:
https://lore.kernel.org/all/[email protected]/
Ido Schimmel (2):
devlink: Split dpipe tables output to a separate function
devlink: Move dpipe tables query to resources show callback
Or Har-Toov (5):
devlink: fix memory leak in resource_ctx_fini
devlink: add dump support for resource show
devlink: show port resources in resource dump
devlink: add per-port resource show support
devlink: add scope filter to resource show
bash-completion/devlink | 8 ++ devlink/devlink.c | 202 +++++++++++++++++++++++++++--------- man/man8/devlink-resource.8 | 34 +++++- 3 files changed, 192 insertions(+), 52 deletions(-)
base-commit: 7340b539841dc739bc0b813e8e86825bc1eb5a4c
Signature · 1 line
2.44.0
PATCH 1/7 devlink: Split dpipe tables output to a separate function
From: Ido Schimmel <[email protected]>
As part of showing device resources, devlink also iterates over available dpipe tables and shows the associated tables, if any.
A subsequent patch will show the device resources even if we failed to retrieve the dpipe tables. In preparation for this change, split the functionality of showing the associated dpipe tables into a separate function.
No functional changes intended.
--- devlink/devlink.c | 54 +++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 23 deletions(-)
devlink/devlink.c +31 -23
@@ -8811,34 +8811,13 @@ static const char *resource_unit_str_get(enum devlink_resource_unit unit) } } -static void resource_show (struct resource *resource, -struct resource_ctx *ctx) +static void resource_dpipe_tables_show (const struct resource *resource, +const struct resource_ctx *ctx) { -struct resource *child_resource;struct dpipe_table *table;struct dl *dl = ctx->dl;bool array = false; -check_indent_newline (dl); -print_string (PRINT_ANY ,"name" ,"name %s" , resource->name); -if (dl->verbose) -resource_path_print (dl, ctx->resources, resource->id); -pr_out_u64 (dl,"size" , resource->size); -if (resource->size != resource->size_new) -pr_out_u64 (dl,"size_new" , resource->size_new); -if (resource->occ_valid) -print_uint (PRINT_ANY ,"occ" ," occ %u" , resource->size_occ); -print_string (PRINT_ANY ,"unit" ," unit %s" , -resource_unit_str_get (resource->unit)); - -if (resource->size_min != resource->size_max) { -print_uint (PRINT_ANY ,"size_min" ," size_min %u" , - resource->size_min); -pr_out_u64 (dl,"size_max" , resource->size_max); -print_uint (PRINT_ANY ,"size_gran" ," size_gran %u" , - resource->size_gran); - } -list_for_each_entry (table, &ctx->tables->table_list, list)if (table->resource_id == resource->id && table->resource_valid)
@@ -8862,6 +8841,35 @@ static void resource_show(struct resource *resource, }if (array)pr_out_array_end (dl); +} + +static void resource_show (struct resource *resource, +struct resource_ctx *ctx) +{ +struct resource *child_resource; +struct dl *dl = ctx->dl; + +check_indent_newline (dl); +print_string (PRINT_ANY ,"name" ,"name %s" , resource->name); +if (dl->verbose) +resource_path_print (dl, ctx->resources, resource->id); +pr_out_u64 (dl,"size" , resource->size); +if (resource->size != resource->size_new) +pr_out_u64 (dl,"size_new" , resource->size_new); +if (resource->occ_valid) +print_uint (PRINT_ANY ,"occ" ," occ %u" , resource->size_occ); +print_string (PRINT_ANY ,"unit" ," unit %s" , +resource_unit_str_get (resource->unit)); + +if (resource->size_min != resource->size_max) { +print_uint (PRINT_ANY ,"size_min" ," size_min %u" , + resource->size_min); +pr_out_u64 (dl,"size_max" , resource->size_max); +print_uint (PRINT_ANY ,"size_gran" ," size_gran %u" , + resource->size_gran); + } + +resource_dpipe_tables_show (resource, ctx);if (list_empty (&resource->resource_list))return ;
Signature · 1 line
2.44.0
PATCH 2/7 devlink: Move dpipe tables query to resources show callback
In reply to Tariq ToukanFrom: Ido Schimmel <[email protected]>
As previously explained, as part of showing device resources, devlink queries the device's dpipe tables so that it will be able to show the association between resources and dpipe tables.
Currently, the dpipe tables are queried before the device resources. This will become a problem when devlink is extended to support dumping the resources of all available devices.
Therefore, in preparation for resource dump support, move the querying of the device's dpipe tables to the resources show callback which is invoked per-device.
There is no difference in the output of the resource show command, but one functional difference is that errors in dpipe tables query are not considered fatal. This seems reasonable given that errors are unlikely and that displaying the dpipe tables is secondary to showing the device resources.
--- devlink/devlink.c | 82 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 62 insertions(+), 20 deletions(-)
devlink/devlink.c +62 -20
@@ -8818,6 +8818,9 @@ static void resource_dpipe_tables_show(const struct resource *resource,struct dl *dl = ctx->dl;bool array = false; +if (!ctx->tables) +return ; +list_for_each_entry (table, &ctx->tables->table_list, list)if (table->resource_id == resource->id && table->resource_valid)
@@ -8888,17 +8891,75 @@ static void resource_show(struct resource *resource,pr_out_array_end (dl); } +static void resources_dpipe_tables_init (struct dpipe_ctx *dpipe_ctx, +struct resource_ctx *resource_ctx, +struct nlattr **tb) +{ +const char *bus_name =mnl_attr_get_str (tb[DEVLINK_ATTR_BUS_NAME ]); +const char *dev_name =mnl_attr_get_str (tb[DEVLINK_ATTR_DEV_NAME ]); +struct mnlu_gen_socket nlg_dpipe; +struct dl *dl = resource_ctx->dl; +struct nlmsghdr *nlh; +int err; + + err =dpipe_ctx_init (dpipe_ctx, dl); +if (err) +return ; + + err =mnlu_gen_socket_open (&nlg_dpipe,DEVLINK_GENL_NAME , +DEVLINK_GENL_VERSION ); +if (err) + goto ctx_fini; + + nlh =mnlu_gen_socket_cmd_prepare (&nlg_dpipe, +DEVLINK_CMD_DPIPE_TABLE_GET , +NLM_F_REQUEST ); + +mnl_attr_put_strz (nlh,DEVLINK_ATTR_BUS_NAME , bus_name); +mnl_attr_put_strz (nlh,DEVLINK_ATTR_DEV_NAME , dev_name); + + err =mnlu_gen_socket_sndrcv (&nlg_dpipe, nlh, cmd_dpipe_table_show_cb, + dpipe_ctx); +if (err) + goto socket_close; + + resource_ctx->tables = dpipe_ctx->tables; +mnlu_gen_socket_close (&nlg_dpipe); + +return ; + +socket_close: +mnlu_gen_socket_close (&nlg_dpipe); +ctx_fini: +dpipe_ctx_fini (dpipe_ctx); +} + +static void resources_dpipe_tables_fini (struct dpipe_ctx *dpipe_ctx, +struct resource_ctx *resource_ctx) +{ +if (!resource_ctx->tables) +return ; + + resource_ctx->tables =NULL ; +dpipe_ctx_fini (dpipe_ctx); +} +static void resources_show (struct resource_ctx *ctx,struct nlattr **tb) {struct resources *resources = ctx->resources; +struct dpipe_ctx dpipe_ctx = {};struct resource *resource; +resources_dpipe_tables_init (&dpipe_ctx, ctx, tb); +list_for_each_entry (resource, &resources->resource_list, list) {pr_out_handle_start_arr (ctx->dl, tb);resource_show (resource, ctx);pr_out_handle_end (ctx->dl); } + +resources_dpipe_tables_fini (&dpipe_ctx, ctx); }static int resources_get (struct resource_ctx *ctx,struct nlattr **tb)
@@ -8933,7 +8994,6 @@ static int cmd_resource_dump_cb(const struct nlmsghdr *nlh, void *data)static int cmd_resource_show (struct dl *dl) {struct nlmsghdr *nlh; -struct dpipe_ctx dpipe_ctx = {};struct resource_ctx resource_ctx = {};int err;
@@ -8941,27 +9001,11 @@ static int cmd_resource_show(struct dl *dl)if (err)return err; - nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_DPIPE_TABLE_GET , -NLM_F_REQUEST ); -dl_opts_put (nlh, dl); - - err =dpipe_ctx_init (&dpipe_ctx, dl); -if (err) -return err; - - err =mnlu_gen_socket_sndrcv (&dl->nlg, nlh, cmd_dpipe_table_show_cb, - &dpipe_ctx); -if (err) { -pr_err ("error get tables %s\n" ,strerror (dpipe_ctx.err)); - goto out; - } - err =resource_ctx_init (&resource_ctx, dl);if (err) - goto out; +return err; resource_ctx.print_resources = true; - resource_ctx.tables = dpipe_ctx.tables; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_RESOURCE_DUMP ,NLM_F_REQUEST |NLM_F_ACK );dl_opts_put (nlh, dl);
@@ -8970,8 +9014,6 @@ static int cmd_resource_show(struct dl *dl) &resource_ctx);pr_out_section_end (dl);resource_ctx_fini (&resource_ctx); -out: -dpipe_ctx_fini (&dpipe_ctx);return err; }
Signature · 1 line
2.44.0
PATCH 3/7 devlink: fix memory leak in resource_ctx_fini
In reply to Tariq ToukanFrom: Or Har-Toov <[email protected]>
resource_ctx_init() allocates ctx->resources via resources_alloc() which calls calloc(). resource_ctx_fini() calls resources_free() to free the list items inside the struct, but never frees the struct itself.
--- devlink/devlink.c | 1 + 1 file changed, 1 insertion(+)
devlink/devlink.c +1 -0
@@ -7441,6 +7441,7 @@ static int resource_ctx_init(struct resource_ctx *ctx, struct dl *dl)static void resource_ctx_fini (struct resource_ctx *ctx) {resources_free (ctx->resources); +free (ctx->resources); }struct dpipe_ctx {
Signature · 1 line
2.44.0
PATCH 4/7 devlink: add dump support for resource show
In reply to Tariq ToukanFrom: Or Har-Toov <[email protected]>
Allow 'devlink resource show' without specifying a device to dump resources from all devlink devices.
--- devlink/devlink.c | 18 ++++++++++++++---- man/man8/devlink-resource.8 | 10 ++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-)
devlink/devlink.c +14 -4
@@ -7429,6 +7429,12 @@ static void resources_free(struct resources *resources)resource_free (resource); } +static void resources_reset (struct resources *resources) +{ +resources_free (resources); +INIT_LIST_HEAD (&resources->resource_list); +} +static int resource_ctx_init (struct resource_ctx *ctx,struct dl *dl) { ctx->resources =resources_alloc ();
@@ -8986,19 +8992,23 @@ static int cmd_resource_dump_cb(const struct nlmsghdr *nlh, void *data)return MNL_CB_ERROR ; } -if (ctx->print_resources) +if (ctx->print_resources) {resources_show (ctx, tb); +resources_reset (ctx->resources); + }return MNL_CB_OK ; }static int cmd_resource_show (struct dl *dl) { +uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;struct nlmsghdr *nlh;struct resource_ctx resource_ctx = {};int err; - err =dl_argv_parse (dl,DL_OPT_HANDLE ,0 ); + err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_RESOURCE_DUMP , +DL_OPT_HANDLE ,0 ,0 ,0 );if (err)return err;
@@ -9008,7 +9018,7 @@ static int cmd_resource_show(struct dl *dl) resource_ctx.print_resources = true; nlh =mnlu_gen_socket_cmd_prepare (&dl->nlg,DEVLINK_CMD_RESOURCE_DUMP , -NLM_F_REQUEST |NLM_F_ACK ); + flags);dl_opts_put (nlh, dl);pr_out_section_start (dl,"resources" ); err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_resource_dump_cb,
@@ -9020,7 +9030,7 @@ static int cmd_resource_show(struct dl *dl)static void cmd_resource_help (void ) { -pr_err ("Usage: devlink resource show DEV\n" +pr_err ("Usage: devlink resource show [ DEV ]\n" " devlink resource set DEV path PATH size SIZE\n" ); }
man/man8/devlink-resource.8 +8 -2
@@ -19,7 +19,7 @@ devlink-resource \- devlink device resource configuration .ti -8 .B devlink resource show -.IR DEV +.RI "[ " DEV " ]" .ti -8 .B devlink resource help
@@ -31,11 +31,12 @@ devlink-resource \- devlink device resource configuration .BI size " RESOURCE_SIZE" .SH "DESCRIPTION" -.SS devlink resource show - display devlink device's resosources +.SS devlink resource show - display devlink device resources .PP .I "DEV" - specifies the devlink device to show. +If omitted, all devices are listed. .in +4 Format is:
@@ -58,6 +59,11 @@ The new resource's size. .SH "EXAMPLES" .PP +devlink resource show +.RS 4 +Shows resources for all devlink devices. +.RE +.PP devlink resource show pci/0000:01:00.0 .RS 4 Shows the resources of the specified devlink device.
Signature · 1 line
2.44.0
PATCH 5/7 devlink: show port resources in resource dump
In reply to Tariq ToukanFrom: Or Har-Toov <[email protected]>
When the kernel returns port-level resource messages during a DEVLINK_CMD_RESOURCE_DUMP, display them alongside device-level resources.
For example:
$ devlink resource show pci/0000:03:00.0: name max_local_SFs size 32 unit entry dpipe_tables none name max_external_SFs size 32 unit entry dpipe_tables none pci/0000:03:00.0/196608: name max_SFs size 32 unit entry dpipe_tables none pci/0000:03:00.1: name max_local_SFs size 32 unit entry dpipe_tables none name max_external_SFs size 32 unit entry dpipe_tables none pci/0000:03:00.1/262144: name max_SFs size 32 unit entry dpipe_tables none
--- devlink/devlink.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
devlink/devlink.c +11 -6
@@ -8954,18 +8954,23 @@ static void resources_dpipe_tables_fini(struct dpipe_ctx *dpipe_ctx,static void resources_show (struct resource_ctx *ctx,struct nlattr **tb) { -struct resources *resources = ctx->resources; +bool is_port = !!tb[DEVLINK_ATTR_PORT_INDEX ];struct dpipe_ctx dpipe_ctx = {};struct resource *resource; +struct dl *dl = ctx->dl;resources_dpipe_tables_init (&dpipe_ctx, ctx, tb); - -list_for_each_entry (resource, &resources->resource_list, list) { -pr_out_handle_start_arr (ctx->dl, tb); +list_for_each_entry (resource, &ctx->resources->resource_list, list) { +if (is_port) +pr_out_port_handle_start_arr (dl, tb, false); +else +pr_out_handle_start_arr (dl, tb);resource_show (resource, ctx); -pr_out_handle_end (ctx->dl); +if (is_port) +pr_out_port_handle_end (dl); +else +pr_out_handle_end (dl); } -resources_dpipe_tables_fini (&dpipe_ctx, ctx); }
Signature · 1 line
2.44.0
PATCH 6/7 devlink: add per-port resource show support
In reply to Tariq ToukanFrom: Or Har-Toov <[email protected]>
Extend 'devlink resource show' to accept DEV/PORT_INDEX, sending DEVLINK_ATTR_PORT_INDEX to the kernel so it returns only that port's resources directly.
For example:
$ devlink resource show pci/0000:03:00.0/196608 pci/0000:03:00.0/196608: name max_SFs size 128 unit entry dpipe_tables none
--- bash-completion/devlink | 1 + devlink/devlink.c | 5 +++-- man/man8/devlink-resource.8 | 17 ++++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-)
bash-completion/devlink +1 -0
@@ -704,6 +704,7 @@ _devlink_resource() show) if [[ $cword -eq 3 ]]; then _devlink_direct_complete "dev" + _devlink_direct_complete "port" fi return ;;
devlink/devlink.c +3 -2
@@ -9013,7 +9013,8 @@ static int cmd_resource_show(struct dl *dl)int err; err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_RESOURCE_DUMP , -DL_OPT_HANDLE ,0 ,0 ,0 ); +DL_OPT_HANDLE |DL_OPT_HANDLEP , +0 ,0 ,0 );if (err)return err;
@@ -9035,7 +9036,7 @@ static int cmd_resource_show(struct dl *dl)static void cmd_resource_help (void ) { -pr_err ("Usage: devlink resource show [ DEV ]\n" +pr_err ("Usage: devlink resource show [ DEV[/PORT_INDEX] ]\n" " devlink resource set DEV path PATH size SIZE\n" ); }
man/man8/devlink-resource.8 +16 -1
@@ -19,7 +19,7 @@ devlink-resource \- devlink device resource configuration .ti -8 .B devlink resource show -.RI "[ " DEV " ]" +.RI "[ " DEV "[/" PORT_INDEX "] ]" .ti -8 .B devlink resource help
@@ -43,6 +43,16 @@ Format is: .in +2 BUS_NAME/BUS_ADDRESS +.PP +.I "PORT_INDEX" +- specifies the port to show resources for. +When given, only port-level resources for that port are shown. + +.in +4 +Format is: +.in +2 +BUS_NAME/BUS_ADDRESS/PORT_INDEX + .SS devlink resource set - sets resource size of specific resource .PP
@@ -69,6 +79,11 @@ devlink resource show pci/0000:01:00.0 Shows the resources of the specified devlink device. .RE .PP +devlink resource show pci/0000:01:00.0/1 +.RS 4 +Shows port-level resources for port 1 of the specified devlink device. +.RE +.PP devlink resource set pci/0000:01:00.0 path /kvd/linear size 98304 .RS 4 Sets the size of the specified resource for the specified devlink device.
Signature · 1 line
2.44.0
PATCH 7/7 devlink: add scope filter to resource show
In reply to Tariq ToukanFrom: Or Har-Toov <[email protected]>
Add optional 'scope { dev | port }' argument to 'devlink resource show' without a device handle to filter the full dump to device-level or port-level resources only.
Example - dump only device-level resources:
$ devlink resource show scope dev
pci/0000:03:00.0:
name max_local_SFs size 128 unit entry dpipe_tables none
name max_external_SFs size 128 unit entry dpipe_tables none
pci/0000:03:00.1:
name max_local_SFs size 128 unit entry dpipe_tables none
name max_external_SFs size 128 unit entry dpipe_tables noneExample - dump only port-level resources:
$ devlink resource show scope port
pci/0000:03:00.0/196608:
name max_SFs size 128 unit entry dpipe_tables none
pci/0000:03:00.0/196609:
name max_SFs size 128 unit entry dpipe_tables none
pci/0000:03:00.1/196708:
name max_SFs size 128 unit entry dpipe_tables none
pci/0000:03:00.1/196709:
name max_SFs size 128 unit entry dpipe_tables none--- bash-completion/devlink | 7 ++++++ devlink/devlink.c | 47 ++++++++++++++++++++++++++++++++----- man/man8/devlink-resource.8 | 11 ++++++++- 3 files changed, 58 insertions(+), 7 deletions(-)
bash-completion/devlink +7 -0
@@ -702,9 +702,16 @@ _devlink_resource() { case $command in show) + case $prev in + scope) + COMPREPLY=( $( compgen -W "dev port" -- "$cur" ) ) + return + ;; + esac if [[ $cword -eq 3 ]]; then _devlink_direct_complete "dev" _devlink_direct_complete "port" + COMPREPLY+=( $( compgen -W "scope" -- "$cur" ) ) fi return ;;
devlink/devlink.c +41 -6
91 lines not on this page · raw message
man/man8/devlink-resource.8 +10 -1
@@ -19,7 +19,7 @@ devlink-resource \- devlink device resource configuration .ti -8 .B devlink resource show -.RI "[ " DEV "[/" PORT_INDEX "] ]" +.RI "[ " DEV "[/" PORT_INDEX "] | " scope " { " dev " | " port " } ]" .ti -8 .B devlink resource help
@@ -53,6 +53,15 @@ Format is: .in +2 BUS_NAME/BUS_ADDRESS/PORT_INDEX +.TP +.BI scope " { dev | port }" +Filter resources by scope. +.B dev +shows only device-level resources. +.B port +shows only port-level resources. +When omitted, resources of both scopes are shown. + .SS devlink resource set - sets resource size of specific resource .PP
Signature · 1 line
2.44.0
Re: [PATCH iproute2-next 7/7] devlink: add scope filter to resource show
Quoted 13 lines · Tariq Toukan
devlink/devlink.c +2
-5@@ -9010,13 +9029,29 @@ static int cmd_resource_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;struct nlmsghdr *nlh;struct resource_ctx resource_ctx = {}; +struct dl_opts *opts = &dl->opts;int err; - err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_RESOURCE_DUMP , -DL_OPT_HANDLE |DL_OPT_HANDLEP , -0 ,0 ,0 ); -if (err) -return err; +if (dl_argv_match (dl,"scope" )) {
devlink/devlink.c static int cmd_resource_show(struct dl *dl) · line 9045
Quoted 10 lines
devlink/devlink.c +10
-0+const char *scopestr; + +dl_arg_inc (dl); + err =dl_argv_str (dl, &scopestr); +if (err) +return err; + err =resource_scope_get (scopestr, &opts->resource_scope_mask); +if (err) +return err; + opts->present |=DL_OPT_RESOURCE_SCOPE ;
Comment from Claude that seems legit:
Issue found: In cmd_resource_show, the scope path sets opts->present |= DL_OPT_RESOURCE_SCOPE without first clearing opts->present. In batch mode, dl->opts is shared across commands, and the non-scope path correctly resets opts->present via dl_argv_parse(). But the scope path bypasses dl_argv_parse(), so stale bits (e.g. DL_OPT_HANDLE from a previous dev show) remain. When dl_opts_put() runs, it writes the stale DEVLINK_ATTR_BUS_NAME/DEV_NAME attributes into the dump request, silently filtering to a single device instead of all devices. Fix: use = instead of |=
Are you ok with the suggested resolution?
Re: [PATCH iproute2-next 7/7] devlink: add scope filter to resource show
Quoted 38 lines · David Ahern
Quoted 13 lines · Tariq Toukan
devlink/devlink.c +2
-5@@ -9010,13 +9029,29 @@ static int cmd_resource_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;struct nlmsghdr *nlh;struct resource_ctx resource_ctx = {}; +struct dl_opts *opts = &dl->opts;int err; - err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_RESOURCE_DUMP , -DL_OPT_HANDLE |DL_OPT_HANDLEP , -0 ,0 ,0 ); -if (err) -return err; +if (dl_argv_match (dl,"scope" )) {devlink/devlink.c static int cmd_resource_show(struct dl *dl) · line 9045
Quoted 10 lines
devlink/devlink.c +10
-0+const char *scopestr; + +dl_arg_inc (dl); + err =dl_argv_str (dl, &scopestr); +if (err) +return err; + err =resource_scope_get (scopestr, &opts->resource_scope_mask); +if (err) +return err; + opts->present |=DL_OPT_RESOURCE_SCOPE ;Comment from Claude that seems legit:
Issue found: In
cmd_resource_show, the scope path setsopts->present|=DL_OPT_RESOURCE_SCOPEwithout first clearingopts->present. In batch mode,dl->optsis shared across commands, and the non-scope path correctly resetsopts->presentviadl_argv_parse(). But the scope path bypassesdl_argv_parse(), so stale bits (e.g.DL_OPT_HANDLEfrom a previous dev show) remain. Whendl_opts_put()runs, it writes the stale DEVLINK_ATTR_BUS_NAME/DEV_NAME attributes into the dump request, silently filtering to a single device instead of all devices. Fix: use = instead of |=
Quoted 2 lines
Are you ok with the suggested resolution?
yes, thank you. let me know if I should resend.
Re: [PATCH iproute2-next 7/7] devlink: add scope filter to resource show
In reply to David AhernQuoted 38 lines · David Ahern
Quoted 13 lines · Tariq Toukan
devlink/devlink.c +2
-5@@ -9010,13 +9029,29 @@ static int cmd_resource_show(struct dl *dl)uint16_t flags =NLM_F_REQUEST |NLM_F_ACK ;struct nlmsghdr *nlh;struct resource_ctx resource_ctx = {}; +struct dl_opts *opts = &dl->opts;int err; - err =dl_argv_parse_with_selector (dl, &flags,DEVLINK_CMD_RESOURCE_DUMP , -DL_OPT_HANDLE |DL_OPT_HANDLEP , -0 ,0 ,0 ); -if (err) -return err; +if (dl_argv_match (dl,"scope" )) {devlink/devlink.c static int cmd_resource_show(struct dl *dl) · line 9045
Quoted 10 lines
devlink/devlink.c +10
-0+const char *scopestr; + +dl_arg_inc (dl); + err =dl_argv_str (dl, &scopestr); +if (err) +return err; + err =resource_scope_get (scopestr, &opts->resource_scope_mask); +if (err) +return err; + opts->present |=DL_OPT_RESOURCE_SCOPE ;Comment from Claude that seems legit:
Issue found: In
cmd_resource_show, the scope path setsopts->present|=DL_OPT_RESOURCE_SCOPEwithout first clearingopts->present. In batch mode,dl->optsis shared across commands, and the non-scope path correctly resetsopts->presentviadl_argv_parse(). But the scope path bypassesdl_argv_parse(), so stale bits (e.g.DL_OPT_HANDLEfrom a previous dev show) remain. Whendl_opts_put()runs, it writes the stale DEVLINK_ATTR_BUS_NAME/DEV_NAME attributes into the dump request, silently filtering to a single device instead of all devices. Fix: use = instead of |=
Quoted 2 lines
Are you ok with the suggested resolution?
yes, thank you. let me know if I should resend.
David Ahern
AppliedQuoted 66 lines · Tariq Toukan
Hi,
Currently, devlink resource show only supports querying a specific device and displays device-level resources. However, some resources are per-port, such as the maximum number of SFs that can be created on a specific PF port.
This series extends devlink resource show with full support for port-level resources, including a dump mode, per-port querying syntax, and scope filtering. In preparation for these features, the first two patches refactor how dpipe tables are handled to unblock dump support and ensure errors in secondary queries are non-fatal.
The series is organized as follows:
Patch 1 splits the dpipe tables display into a separate function.
Patch 2 moves the dpipe tables query into the per-device resource show callback, ensuring it behaves correctly during a multi-device dump.
Patch 3 fixes a pre-existing memory leak in
resource_ctx_fini.Patch 4 adds dump support to resource show (no device required).
Patch 5 shows port-level resources returned in a dump reply.
Patch 6 adds DEV/PORT_INDEX syntax to resource show.
Patch 7 adds scope filter to resource show.
With this series, users can query resources at all levels:
$ devlink resource show pci/0000:03:00.0: name local_max_SFs size 508 unit entry name external_max_SFs size 508 unit entry pci/0000:03:00.0/196608: name max_SFs size 20 unit entry$ devlink resource show scope dev pci/0000:03:00.0: name local_max_SFs size 508 unit entry name external_max_SFs size 508 unit entry$ devlink resource show scope port pci/0000:03:00.0/196608: name max_SFs size 20 unit entry$ devlink resource show pci/0000:03:00.0/196608 pci/0000:03:00.0/196608: name max_SFs size 20 unit entryThis series is the userspace counterpart to the kernel series:
https://lore.kernel.org/all/[email protected]/Ido Schimmel (2):
devlink: Split dpipe tables output to a separate function
devlink: Move dpipe tables query to resources show callbackOr Har-Toov (5):
devlink: fix memory leak inresource_ctx_fini
devlink: add dump support for resource show
devlink: show port resources in resource dump
devlink: add per-port resource show support
devlink: add scope filter to resource show
Quoted 7 lines
bash-completion/devlink | 8 ++ devlink/devlink.c | 202 +++++++++++++++++++++++++++--------- man/man8/devlink-resource.8 | 34 +++++- 3 files changed, 192 insertions(+), 52 deletions(-)base-commit:
7340b539841dc739bc0b813e8e86825bc1eb5a4c
applied to iproute2-next with the fixup recommended by Claude and confirmed by Or