Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

devlink: Add port-specific option to resource dump doit

Allow querying devlink resources per-port via the resource-dump doit
handler. When a port-index attribute is provided, only that port's
resources are returned. When no port-index is given, only device-level
resources are returned, preserving backward compatibility.

Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260407194107.148063-8-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Or Har-Toov and committed by
Jakub Kicinski
7511ff14 810b7639

+24 -7
+3 -1
Documentation/netlink/specs/devlink.yaml
··· 1757 1757 attribute-set: devlink 1758 1758 dont-validate: [strict] 1759 1759 do: 1760 - pre: devlink-nl-pre-doit 1760 + pre: devlink-nl-pre-doit-port-optional 1761 1761 post: devlink-nl-post-doit 1762 1762 request: 1763 1763 attributes: 1764 1764 - bus-name 1765 1765 - dev-name 1766 1766 - index 1767 + - port-index 1767 1768 reply: &resource-dump-reply 1768 1769 value: 36 1769 1770 attributes: 1770 1771 - bus-name 1771 1772 - dev-name 1772 1773 - index 1774 + - port-index 1773 1775 - resource-list 1774 1776 dump: 1775 1777 request:
+17 -3
net/devlink/resource.c
··· 251 251 static int devlink_resource_fill(struct genl_info *info, 252 252 enum devlink_command cmd, int flags) 253 253 { 254 + struct devlink_port *devlink_port = info->user_ptr[1]; 254 255 struct devlink *devlink = info->user_ptr[0]; 255 256 struct devlink_resource *resource; 257 + struct list_head *resource_list; 256 258 struct nlattr *resources_attr; 257 259 struct sk_buff *skb = NULL; 258 260 struct nlmsghdr *nlh; ··· 263 261 int i; 264 262 int err; 265 263 266 - resource = list_first_entry(&devlink->resource_list, 264 + resource_list = devlink_port ? 265 + &devlink_port->resource_list : &devlink->resource_list; 266 + resource = list_first_entry(resource_list, 267 267 struct devlink_resource, list); 268 268 start_again: 269 269 err = devlink_nl_msg_reply_and_new(&skb, info); ··· 281 277 282 278 if (devlink_nl_put_handle(skb, devlink)) 283 279 goto nla_put_failure; 280 + if (devlink_port && 281 + nla_put_u32(skb, DEVLINK_ATTR_PORT_INDEX, devlink_port->index)) 282 + goto nla_put_failure; 284 283 285 284 resources_attr = nla_nest_start_noflag(skb, 286 285 DEVLINK_ATTR_RESOURCE_LIST); ··· 292 285 293 286 incomplete = false; 294 287 i = 0; 295 - list_for_each_entry_from(resource, &devlink->resource_list, list) { 288 + list_for_each_entry_from(resource, resource_list, list) { 296 289 err = devlink_resource_put(devlink, skb, resource); 297 290 if (err) { 298 291 if (!i) ··· 326 319 327 320 int devlink_nl_resource_dump_doit(struct sk_buff *skb, struct genl_info *info) 328 321 { 322 + struct devlink_port *devlink_port = info->user_ptr[1]; 329 323 struct devlink *devlink = info->user_ptr[0]; 324 + struct list_head *resource_list; 330 325 331 - if (list_empty(&devlink->resource_list)) 326 + if (info->attrs[DEVLINK_ATTR_PORT_INDEX] && !devlink_port) 327 + return -ENODEV; 328 + 329 + resource_list = devlink_port ? 330 + &devlink_port->resource_list : &devlink->resource_list; 331 + if (list_empty(resource_list)) 332 332 return -EOPNOTSUPP; 333 333 334 334 return devlink_resource_fill(info, DEVLINK_CMD_RESOURCE_DUMP, 0);