Skip to content

Commit f3cc003

Browse files
committed
Merge branch 'devlink-introduce-selective-dumps'
Jiri Pirko says: ==================== devlink: introduce selective dumps Motivation: For SFs, one devlink instance per SF is created. There might be thousands of these on a single host. When a user needs to know port handle for specific SF, he needs to dump all devlink ports on the host which does not scale good. Solution: Allow user to pass devlink handle (and possibly other attributes) alongside the dump command and dump only objects which are matching the selection. Use split ops to generate policies for dump callbacks acccording to the attributes used for selection. The userspace can use ctrl genetlink GET_POLICY command to find out if the selective dumps are supported by kernel for particular command. Example: $ devlink port show auxiliary/mlx5_core.eth.0/65535: type eth netdev eth2 flavour physical port 0 splittable false auxiliary/mlx5_core.eth.1/131071: type eth netdev eth3 flavour physical port 1 splittable false $ devlink port show auxiliary/mlx5_core.eth.0 auxiliary/mlx5_core.eth.0/65535: type eth netdev eth2 flavour physical port 0 splittable false $ devlink port show auxiliary/mlx5_core.eth.1 auxiliary/mlx5_core.eth.1/131071: type eth netdev eth3 flavour physical port 1 splittable false Extension: patches #12 and torvalds#13 extends selection attributes by port index for health reporter dumping. ==================== Link: https://lore.kernel.org/r/20230811155714.1736405-1-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 83b5f02 + 0149bca commit f3cc003

File tree

10 files changed

+5327
-506
lines changed

10 files changed

+5327
-506
lines changed

Documentation/netlink/specs/devlink.yaml

+456-1
Large diffs are not rendered by default.

net/devlink/dev.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,11 @@ int devlink_nl_get_doit(struct sk_buff *skb, struct genl_info *info)
218218

219219
static int
220220
devlink_nl_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
221-
struct netlink_callback *cb)
221+
struct netlink_callback *cb, int flags)
222222
{
223223
return devlink_nl_fill(msg, devlink, DEVLINK_CMD_NEW,
224224
NETLINK_CB(cb->skb).portid,
225-
cb->nlh->nlmsg_seq, NLM_F_MULTI);
225+
cb->nlh->nlmsg_seq, flags);
226226
}
227227

228228
int devlink_nl_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
@@ -828,13 +828,13 @@ int devlink_nl_info_get_doit(struct sk_buff *skb, struct genl_info *info)
828828

829829
static int
830830
devlink_nl_info_get_dump_one(struct sk_buff *msg, struct devlink *devlink,
831-
struct netlink_callback *cb)
831+
struct netlink_callback *cb, int flags)
832832
{
833833
int err;
834834

835835
err = devlink_nl_info_fill(msg, devlink, DEVLINK_CMD_INFO_GET,
836836
NETLINK_CB(cb->skb).portid,
837-
cb->nlh->nlmsg_seq, NLM_F_MULTI,
837+
cb->nlh->nlmsg_seq, flags,
838838
cb->extack);
839839
if (err == -EOPNOTSUPP)
840840
err = 0;
@@ -1206,8 +1206,7 @@ devlink_nl_selftests_fill(struct sk_buff *msg, struct devlink *devlink,
12061206
return err;
12071207
}
12081208

1209-
int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb,
1210-
struct genl_info *info)
1209+
int devlink_nl_selftests_get_doit(struct sk_buff *skb, struct genl_info *info)
12111210
{
12121211
struct devlink *devlink = info->user_ptr[0];
12131212
struct sk_buff *msg;
@@ -1230,23 +1229,25 @@ int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb,
12301229
return genlmsg_reply(msg, info);
12311230
}
12321231

1233-
static int
1234-
devlink_nl_cmd_selftests_get_dump_one(struct sk_buff *msg,
1235-
struct devlink *devlink,
1236-
struct netlink_callback *cb)
1232+
static int devlink_nl_selftests_get_dump_one(struct sk_buff *msg,
1233+
struct devlink *devlink,
1234+
struct netlink_callback *cb,
1235+
int flags)
12371236
{
12381237
if (!devlink->ops->selftest_check)
12391238
return 0;
12401239

12411240
return devlink_nl_selftests_fill(msg, devlink,
12421241
NETLINK_CB(cb->skb).portid,
1243-
cb->nlh->nlmsg_seq, NLM_F_MULTI,
1242+
cb->nlh->nlmsg_seq, flags,
12441243
cb->extack);
12451244
}
12461245

1247-
const struct devlink_cmd devl_cmd_selftests_get = {
1248-
.dump_one = devlink_nl_cmd_selftests_get_dump_one,
1249-
};
1246+
int devlink_nl_selftests_get_dumpit(struct sk_buff *skb,
1247+
struct netlink_callback *cb)
1248+
{
1249+
return devlink_nl_dumpit(skb, cb, devlink_nl_selftests_get_dump_one);
1250+
}
12501251

12511252
static int devlink_selftest_result_put(struct sk_buff *skb, unsigned int id,
12521253
enum devlink_selftest_status test_status)

net/devlink/devl_internal.h

+4-40
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,6 @@ static inline bool devl_is_registered(struct devlink *devlink)
9292
/* Netlink */
9393
#define DEVLINK_NL_FLAG_NEED_PORT BIT(0)
9494
#define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1)
95-
#define DEVLINK_NL_FLAG_NEED_RATE BIT(2)
96-
#define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3)
97-
#define DEVLINK_NL_FLAG_NEED_LINECARD BIT(4)
9895

9996
enum devlink_multicast_groups {
10097
DEVLINK_MCGRP_CONFIG,
@@ -118,13 +115,10 @@ struct devlink_nl_dump_state {
118115

119116
typedef int devlink_nl_dump_one_func_t(struct sk_buff *msg,
120117
struct devlink *devlink,
121-
struct netlink_callback *cb);
118+
struct netlink_callback *cb,
119+
int flags);
122120

123-
struct devlink_cmd {
124-
devlink_nl_dump_one_func_t *dump_one;
125-
};
126-
127-
extern const struct genl_small_ops devlink_nl_small_ops[54];
121+
extern const struct genl_small_ops devlink_nl_small_ops[40];
128122

129123
struct devlink *
130124
devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs);
@@ -134,7 +128,6 @@ void devlink_notify_register(struct devlink *devlink);
134128

135129
int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb,
136130
devlink_nl_dump_one_func_t *dump_one);
137-
int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, struct netlink_callback *cb);
138131

139132
static inline struct devlink_nl_dump_state *
140133
devlink_dump_state(struct netlink_callback *cb)
@@ -154,22 +147,6 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink)
154147
return 0;
155148
}
156149

157-
/* Commands */
158-
extern const struct devlink_cmd devl_cmd_port_get;
159-
extern const struct devlink_cmd devl_cmd_sb_get;
160-
extern const struct devlink_cmd devl_cmd_sb_pool_get;
161-
extern const struct devlink_cmd devl_cmd_sb_port_pool_get;
162-
extern const struct devlink_cmd devl_cmd_sb_tc_pool_bind_get;
163-
extern const struct devlink_cmd devl_cmd_param_get;
164-
extern const struct devlink_cmd devl_cmd_region_get;
165-
extern const struct devlink_cmd devl_cmd_health_reporter_get;
166-
extern const struct devlink_cmd devl_cmd_trap_get;
167-
extern const struct devlink_cmd devl_cmd_trap_group_get;
168-
extern const struct devlink_cmd devl_cmd_trap_policer_get;
169-
extern const struct devlink_cmd devl_cmd_rate_get;
170-
extern const struct devlink_cmd devl_cmd_linecard_get;
171-
extern const struct devlink_cmd devl_cmd_selftests_get;
172-
173150
/* Notify */
174151
void devlink_notify(struct devlink *devlink, enum devlink_command cmd);
175152

@@ -203,29 +180,16 @@ int devlink_resources_validate(struct devlink *devlink,
203180
struct devlink_resource *resource,
204181
struct genl_info *info);
205182

206-
/* Line cards */
207-
struct devlink_linecard;
208-
209-
struct devlink_linecard *
210-
devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info);
211-
212183
/* Rates */
213184
int devlink_rate_nodes_check(struct devlink *devlink, u16 mode,
214185
struct netlink_ext_ack *extack);
215-
struct devlink_rate *
216-
devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info);
217-
struct devlink_rate *
218-
devlink_rate_node_get_from_info(struct devlink *devlink,
219-
struct genl_info *info);
186+
220187
/* Devlink nl cmds */
221188
int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info);
222189
int devlink_nl_cmd_eswitch_get_doit(struct sk_buff *skb, struct genl_info *info);
223190
int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info);
224191
int devlink_nl_cmd_flash_update(struct sk_buff *skb, struct genl_info *info);
225-
int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb, struct genl_info *info);
226192
int devlink_nl_cmd_selftests_run(struct sk_buff *skb, struct genl_info *info);
227-
int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
228-
struct genl_info *info);
229193
int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
230194
struct genl_info *info);
231195
int devlink_nl_cmd_health_reporter_recover_doit(struct sk_buff *skb,

net/devlink/health.c

+28-12
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ devlink_health_reporter_get_from_info(struct devlink *devlink,
356356
return devlink_health_reporter_get_from_attrs(devlink, info->attrs);
357357
}
358358

359-
int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
360-
struct genl_info *info)
359+
int devlink_nl_health_reporter_get_doit(struct sk_buff *skb,
360+
struct genl_info *info)
361361
{
362362
struct devlink *devlink = info->user_ptr[0];
363363
struct devlink_health_reporter *reporter;
@@ -384,18 +384,29 @@ int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb,
384384
return genlmsg_reply(msg, info);
385385
}
386386

387-
static int
388-
devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg,
389-
struct devlink *devlink,
390-
struct netlink_callback *cb)
387+
static int devlink_nl_health_reporter_get_dump_one(struct sk_buff *msg,
388+
struct devlink *devlink,
389+
struct netlink_callback *cb,
390+
int flags)
391391
{
392392
struct devlink_nl_dump_state *state = devlink_dump_state(cb);
393+
const struct genl_dumpit_info *info = genl_dumpit_info(cb);
393394
struct devlink_health_reporter *reporter;
395+
unsigned long port_index_end = ULONG_MAX;
396+
struct nlattr **attrs = info->attrs;
397+
unsigned long port_index_start = 0;
394398
struct devlink_port *port;
395399
unsigned long port_index;
396400
int idx = 0;
397401
int err;
398402

403+
if (attrs && attrs[DEVLINK_ATTR_PORT_INDEX]) {
404+
port_index_start = nla_get_u32(attrs[DEVLINK_ATTR_PORT_INDEX]);
405+
port_index_end = port_index_start;
406+
flags |= NLM_F_DUMP_FILTERED;
407+
goto per_port_dump;
408+
}
409+
399410
list_for_each_entry(reporter, &devlink->reporter_list, list) {
400411
if (idx < state->idx) {
401412
idx++;
@@ -405,14 +416,16 @@ devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg,
405416
DEVLINK_CMD_HEALTH_REPORTER_GET,
406417
NETLINK_CB(cb->skb).portid,
407418
cb->nlh->nlmsg_seq,
408-
NLM_F_MULTI);
419+
flags);
409420
if (err) {
410421
state->idx = idx;
411422
return err;
412423
}
413424
idx++;
414425
}
415-
xa_for_each(&devlink->ports, port_index, port) {
426+
per_port_dump:
427+
xa_for_each_range(&devlink->ports, port_index, port,
428+
port_index_start, port_index_end) {
416429
list_for_each_entry(reporter, &port->reporter_list, list) {
417430
if (idx < state->idx) {
418431
idx++;
@@ -422,7 +435,7 @@ devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg,
422435
DEVLINK_CMD_HEALTH_REPORTER_GET,
423436
NETLINK_CB(cb->skb).portid,
424437
cb->nlh->nlmsg_seq,
425-
NLM_F_MULTI);
438+
flags);
426439
if (err) {
427440
state->idx = idx;
428441
return err;
@@ -434,9 +447,12 @@ devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg,
434447
return 0;
435448
}
436449

437-
const struct devlink_cmd devl_cmd_health_reporter_get = {
438-
.dump_one = devlink_nl_cmd_health_reporter_get_dump_one,
439-
};
450+
int devlink_nl_health_reporter_get_dumpit(struct sk_buff *skb,
451+
struct netlink_callback *cb)
452+
{
453+
return devlink_nl_dumpit(skb, cb,
454+
devlink_nl_health_reporter_get_dump_one);
455+
}
440456

441457
int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb,
442458
struct genl_info *info)

0 commit comments

Comments
 (0)