diff options
author | Jakub Kicinski <kuba@kernel.org> | 2023-01-05 05:05:26 +0100 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2023-01-06 07:13:39 +0100 |
commit | 731d69a6bd13b7c0cdbd3607edfa681269d54828 (patch) | |
tree | e9a2013115acdc023cd1a363e9fba874e300996d /net/devlink/devl_internal.h | |
parent | devlink: health: combine loops in dump (diff) | |
download | linux-731d69a6bd13b7c0cdbd3607edfa681269d54828.tar.xz linux-731d69a6bd13b7c0cdbd3607edfa681269d54828.zip |
devlink: restart dump based on devlink instance ids (simple)
xarray gives each devlink instance an id and allows us to restart
walk based on that id quite neatly. This is nice both from the
perspective of code brevity and from the stability of the dump
(devlink instances disappearing from before the resumption point
will not cause inconsistent dumps).
This patch takes care of simple cases where state->idx counts
devlink instances only.
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/devlink/devl_internal.h')
-rw-r--r-- | net/devlink/devl_internal.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 86b321aef3eb..b9bb6f73a7c1 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -87,6 +87,10 @@ extern struct genl_family devlink_nl_family; devlink; devlink = devlinks_xa_find_get_next(net, &index)) struct devlink * +devlinks_xa_find_get(struct net *net, unsigned long *indexp, + void * (*xa_find_fn)(struct xarray *, unsigned long *, + unsigned long, xa_mark_t)); +struct devlink * devlinks_xa_find_get_first(struct net *net, unsigned long *indexp); struct devlink * devlinks_xa_find_get_next(struct net *net, unsigned long *indexp); @@ -104,6 +108,7 @@ enum devlink_multicast_groups { /* state held across netlink dumps */ struct devlink_nl_dump_state { + unsigned long instance; int idx; union { /* DEVLINK_CMD_REGION_READ */ @@ -117,6 +122,17 @@ struct devlink_nl_dump_state { }; }; +/* Iterate over registered devlink instances for devlink dump. + * devlink_put() needs to be called for each iterated devlink pointer + * in loop body in order to release the reference. + * Note: this is NOT a generic iterator, it makes assumptions about the use + * of @state and can only be used once per dumpit implementation. + */ +#define devlink_dump_for_each_instance_get(msg, state, devlink) \ + for (; (devlink = devlinks_xa_find_get(sock_net(msg->sk), \ + &state->instance, xa_find)); \ + state->instance++) + extern const struct genl_small_ops devlink_nl_ops[56]; struct devlink *devlink_get_from_attrs(struct net *net, struct nlattr **attrs); |