summaryrefslogtreecommitdiff
path: root/net/devlink/leftover.c
diff options
context:
space:
mode:
authorJiri Pirko <jiri@nvidia.com>2023-08-11 18:57:03 +0300
committerJakub Kicinski <kuba@kernel.org>2023-08-14 21:47:24 +0300
commit41a1d4d1399af0f4ba9754086b23f7b9576eb25f (patch)
tree7e9964de5075acff46d9f75fcba216664880b03c /net/devlink/leftover.c
parent63618463cb94bda3ee68dc2ada998c0ef3c00e67 (diff)
downloadlinux-41a1d4d1399af0f4ba9754086b23f7b9576eb25f.tar.xz
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: Jiri Pirko <jiri@nvidia.com> Acked-by: Jakub Kicinski <kuba@kernel.org> Link: https://lore.kernel.org/r/20230811155714.1736405-3-jiri@resnulli.us Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/devlink/leftover.c')
-rw-r--r--net/devlink/leftover.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c
index 46cdd5d88583..b7b6850e26d8 100644
--- a/net/devlink/leftover.c
+++ b/net/devlink/leftover.c
@@ -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);
}
-struct devlink_rate *
+static struct devlink_rate *
devlink_rate_node_get_from_info(struct devlink *devlink, struct genl_info *info)
{
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)
{
struct nlattr **attrs = info->attrs;
@@ -1041,10 +1041,15 @@ const struct devlink_cmd devl_cmd_rate_get = {
static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb,
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;
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);
if (!msg)
return -ENOMEM;
@@ -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,
struct genl_info *info)
{
- struct devlink_rate *devlink_rate = info->user_ptr[1];
- struct devlink *devlink = devlink_rate->devlink;
- const struct devlink_ops *ops = devlink->ops;
+ struct devlink *devlink = info->user_ptr[0];
+ struct devlink_rate *devlink_rate;
+ const struct devlink_ops *ops;
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))
return -EOPNOTSUPP;
@@ -1704,18 +1714,22 @@ err_strdup:
static int devlink_nl_cmd_rate_del_doit(struct sk_buff *skb,
struct genl_info *info)
{
- struct devlink_rate *rate_node = info->user_ptr[1];
- struct devlink *devlink = rate_node->devlink;
- const struct devlink_ops *ops = devlink->ops;
+ struct devlink *devlink = info->user_ptr[0];
+ struct devlink_rate *rate_node;
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) {
NL_SET_ERR_MSG(info->extack, "Node has children. Cannot delete node.");
return -EBUSY;
}
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)
refcount_dec(&rate_node->parent->refcnt);
list_del(&rate_node->list);
@@ -6307,14 +6321,12 @@ const struct genl_small_ops devlink_nl_small_ops[54] = {
.cmd = DEVLINK_CMD_RATE_GET,
.doit = devlink_nl_cmd_rate_get_doit,
.dumpit = devlink_nl_instance_iter_dumpit,
- .internal_flags = DEVLINK_NL_FLAG_NEED_RATE,
/* can be retrieved by unprivileged users */
},
{
.cmd = DEVLINK_CMD_RATE_SET,
.doit = devlink_nl_cmd_rate_set_doit,
.flags = GENL_ADMIN_PERM,
- .internal_flags = DEVLINK_NL_FLAG_NEED_RATE,
},
{
.cmd = DEVLINK_CMD_RATE_NEW,
@@ -6325,7 +6337,6 @@ const struct genl_small_ops devlink_nl_small_ops[54] = {
.cmd = DEVLINK_CMD_RATE_DEL,
.doit = devlink_nl_cmd_rate_del_doit,
.flags = GENL_ADMIN_PERM,
- .internal_flags = DEVLINK_NL_FLAG_NEED_RATE_NODE,
},
{
.cmd = DEVLINK_CMD_PORT_SPLIT,