Commit 41a1d4d1 authored by Jiri Pirko's avatar Jiri Pirko Committed by Jakub Kicinski

devlink: parse rate attrs in doit() callbacks

No need to give the rate any special treatment in netlink attributes
parsing, as unlike for ports, there is only a couple of commands
benefiting from that.

Remove DEVLINK_NL_FLAG_NEED_RATE*, make pre_doit() callback simpler
by moving the rate attributes parsing to rate_*_doit() ops.
Signed-off-by: default avatarJiri Pirko <jiri@nvidia.com>
Acked-by: default avatarJakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/r/20230811155714.1736405-3-jiri@resnulli.usSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 63618463
...@@ -92,8 +92,6 @@ static inline bool devl_is_registered(struct devlink *devlink) ...@@ -92,8 +92,6 @@ static inline bool devl_is_registered(struct devlink *devlink)
/* Netlink */ /* Netlink */
#define DEVLINK_NL_FLAG_NEED_PORT BIT(0) #define DEVLINK_NL_FLAG_NEED_PORT BIT(0)
#define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1)
#define DEVLINK_NL_FLAG_NEED_RATE BIT(2)
#define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3)
enum devlink_multicast_groups { enum devlink_multicast_groups {
DEVLINK_MCGRP_CONFIG, DEVLINK_MCGRP_CONFIG,
...@@ -205,11 +203,7 @@ int devlink_resources_validate(struct devlink *devlink, ...@@ -205,11 +203,7 @@ int devlink_resources_validate(struct devlink *devlink,
/* Rates */ /* Rates */
int devlink_rate_nodes_check(struct devlink *devlink, u16 mode, int devlink_rate_nodes_check(struct devlink *devlink, u16 mode,
struct netlink_ext_ack *extack); struct netlink_ext_ack *extack);
struct devlink_rate *
devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info);
struct devlink_rate *
devlink_rate_node_get_from_info(struct devlink *devlink,
struct genl_info *info);
/* Devlink nl cmds */ /* Devlink nl cmds */
int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info);
int devlink_nl_cmd_eswitch_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_eswitch_get_doit(struct sk_buff *skb, struct genl_info *info);
......
...@@ -232,13 +232,13 @@ devlink_rate_node_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) ...@@ -232,13 +232,13 @@ devlink_rate_node_get_from_attrs(struct devlink *devlink, struct nlattr **attrs)
return devlink_rate_node_get_by_name(devlink, rate_node_name); return devlink_rate_node_get_by_name(devlink, rate_node_name);
} }
struct devlink_rate * static struct devlink_rate *
devlink_rate_node_get_from_info(struct devlink *devlink, struct genl_info *info) devlink_rate_node_get_from_info(struct devlink *devlink, struct genl_info *info)
{ {
return devlink_rate_node_get_from_attrs(devlink, info->attrs); return devlink_rate_node_get_from_attrs(devlink, info->attrs);
} }
struct devlink_rate * static struct devlink_rate *
devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info) devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info)
{ {
struct nlattr **attrs = info->attrs; struct nlattr **attrs = info->attrs;
...@@ -1041,10 +1041,15 @@ const struct devlink_cmd devl_cmd_rate_get = { ...@@ -1041,10 +1041,15 @@ const struct devlink_cmd devl_cmd_rate_get = {
static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb, static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
struct devlink_rate *devlink_rate = info->user_ptr[1]; struct devlink *devlink = info->user_ptr[0];
struct devlink_rate *devlink_rate;
struct sk_buff *msg; struct sk_buff *msg;
int err; int err;
devlink_rate = devlink_rate_get_from_info(devlink, info);
if (IS_ERR(devlink_rate))
return PTR_ERR(devlink_rate);
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
if (!msg) if (!msg)
return -ENOMEM; return -ENOMEM;
...@@ -1629,11 +1634,16 @@ static bool devlink_rate_set_ops_supported(const struct devlink_ops *ops, ...@@ -1629,11 +1634,16 @@ static bool devlink_rate_set_ops_supported(const struct devlink_ops *ops,
static int devlink_nl_cmd_rate_set_doit(struct sk_buff *skb, static int devlink_nl_cmd_rate_set_doit(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
struct devlink_rate *devlink_rate = info->user_ptr[1]; struct devlink *devlink = info->user_ptr[0];
struct devlink *devlink = devlink_rate->devlink; struct devlink_rate *devlink_rate;
const struct devlink_ops *ops = devlink->ops; const struct devlink_ops *ops;
int err; int err;
devlink_rate = devlink_rate_get_from_info(devlink, info);
if (IS_ERR(devlink_rate))
return PTR_ERR(devlink_rate);
ops = devlink->ops;
if (!ops || !devlink_rate_set_ops_supported(ops, info, devlink_rate->type)) if (!ops || !devlink_rate_set_ops_supported(ops, info, devlink_rate->type))
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -1704,18 +1714,22 @@ static int devlink_nl_cmd_rate_new_doit(struct sk_buff *skb, ...@@ -1704,18 +1714,22 @@ static int devlink_nl_cmd_rate_new_doit(struct sk_buff *skb,
static int devlink_nl_cmd_rate_del_doit(struct sk_buff *skb, static int devlink_nl_cmd_rate_del_doit(struct sk_buff *skb,
struct genl_info *info) struct genl_info *info)
{ {
struct devlink_rate *rate_node = info->user_ptr[1]; struct devlink *devlink = info->user_ptr[0];
struct devlink *devlink = rate_node->devlink; struct devlink_rate *rate_node;
const struct devlink_ops *ops = devlink->ops;
int err; int err;
rate_node = devlink_rate_node_get_from_info(devlink, info);
if (IS_ERR(rate_node))
return PTR_ERR(rate_node);
if (refcount_read(&rate_node->refcnt) > 1) { if (refcount_read(&rate_node->refcnt) > 1) {
NL_SET_ERR_MSG(info->extack, "Node has children. Cannot delete node."); NL_SET_ERR_MSG(info->extack, "Node has children. Cannot delete node.");
return -EBUSY; return -EBUSY;
} }
devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_DEL); devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_DEL);
err = ops->rate_node_del(rate_node, rate_node->priv, info->extack); err = devlink->ops->rate_node_del(rate_node, rate_node->priv,
info->extack);
if (rate_node->parent) if (rate_node->parent)
refcount_dec(&rate_node->parent->refcnt); refcount_dec(&rate_node->parent->refcnt);
list_del(&rate_node->list); list_del(&rate_node->list);
...@@ -6307,14 +6321,12 @@ const struct genl_small_ops devlink_nl_small_ops[54] = { ...@@ -6307,14 +6321,12 @@ const struct genl_small_ops devlink_nl_small_ops[54] = {
.cmd = DEVLINK_CMD_RATE_GET, .cmd = DEVLINK_CMD_RATE_GET,
.doit = devlink_nl_cmd_rate_get_doit, .doit = devlink_nl_cmd_rate_get_doit,
.dumpit = devlink_nl_instance_iter_dumpit, .dumpit = devlink_nl_instance_iter_dumpit,
.internal_flags = DEVLINK_NL_FLAG_NEED_RATE,
/* can be retrieved by unprivileged users */ /* can be retrieved by unprivileged users */
}, },
{ {
.cmd = DEVLINK_CMD_RATE_SET, .cmd = DEVLINK_CMD_RATE_SET,
.doit = devlink_nl_cmd_rate_set_doit, .doit = devlink_nl_cmd_rate_set_doit,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NEED_RATE,
}, },
{ {
.cmd = DEVLINK_CMD_RATE_NEW, .cmd = DEVLINK_CMD_RATE_NEW,
...@@ -6325,7 +6337,6 @@ const struct genl_small_ops devlink_nl_small_ops[54] = { ...@@ -6325,7 +6337,6 @@ const struct genl_small_ops devlink_nl_small_ops[54] = {
.cmd = DEVLINK_CMD_RATE_DEL, .cmd = DEVLINK_CMD_RATE_DEL,
.doit = devlink_nl_cmd_rate_del_doit, .doit = devlink_nl_cmd_rate_del_doit,
.flags = GENL_ADMIN_PERM, .flags = GENL_ADMIN_PERM,
.internal_flags = DEVLINK_NL_FLAG_NEED_RATE_NODE,
}, },
{ {
.cmd = DEVLINK_CMD_PORT_SPLIT, .cmd = DEVLINK_CMD_PORT_SPLIT,
......
...@@ -132,24 +132,6 @@ int devlink_nl_pre_doit(const struct genl_split_ops *ops, ...@@ -132,24 +132,6 @@ int devlink_nl_pre_doit(const struct genl_split_ops *ops,
devlink_port = devlink_port_get_from_info(devlink, info); devlink_port = devlink_port_get_from_info(devlink, info);
if (!IS_ERR(devlink_port)) if (!IS_ERR(devlink_port))
info->user_ptr[1] = devlink_port; info->user_ptr[1] = devlink_port;
} else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_RATE) {
struct devlink_rate *devlink_rate;
devlink_rate = devlink_rate_get_from_info(devlink, info);
if (IS_ERR(devlink_rate)) {
err = PTR_ERR(devlink_rate);
goto unlock;
}
info->user_ptr[1] = devlink_rate;
} else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_RATE_NODE) {
struct devlink_rate *rate_node;
rate_node = devlink_rate_node_get_from_info(devlink, info);
if (IS_ERR(rate_node)) {
err = PTR_ERR(rate_node);
goto unlock;
}
info->user_ptr[1] = rate_node;
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment