]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
devlink: convert linecards dump to devlink_nl_instance_iter_dump()
authorJiri Pirko <jiri@nvidia.com>
Wed, 18 Jan 2023 15:21:12 +0000 (16:21 +0100)
committerJakub Kicinski <kuba@kernel.org>
Fri, 20 Jan 2023 03:08:38 +0000 (19:08 -0800)
Benefit from recently introduced instance iteration and convert
linecards .dumpit generic netlink callback to use it.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/devlink/devl_internal.h
net/devlink/leftover.c
net/devlink/netlink.c

index bdb83014b4b53b79cf59ca14046e8b1dec315372..d8f8e4bff5b48a6970e3a224f8bd95f38621398f 100644 (file)
@@ -167,6 +167,7 @@ extern const struct devlink_gen_cmd devl_gen_info;
 extern const struct devlink_gen_cmd devl_gen_trap;
 extern const struct devlink_gen_cmd devl_gen_trap_group;
 extern const struct devlink_gen_cmd devl_gen_trap_policer;
+extern const struct devlink_gen_cmd devl_gen_linecard;
 
 /* Ports */
 int devlink_port_netdevice_event(struct notifier_block *nb,
index 114baecebaeb182477cd867163ca7c13992a1719..685845a2fc78cf3550a3f3bf1693a1396db05f88 100644 (file)
@@ -2105,50 +2105,42 @@ static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb,
        return genlmsg_reply(msg, info);
 }
 
-static int devlink_nl_cmd_linecard_get_dumpit(struct sk_buff *msg,
-                                             struct netlink_callback *cb)
+static int devlink_nl_cmd_linecard_get_dump_one(struct sk_buff *msg,
+                                               struct devlink *devlink,
+                                               struct netlink_callback *cb)
 {
        struct devlink_nl_dump_state *state = devlink_dump_state(cb);
        struct devlink_linecard *linecard;
-       struct devlink *devlink;
-       int err;
-
-       devlink_dump_for_each_instance_get(msg, state, devlink) {
-               int idx = 0;
-
-               devl_lock(devlink);
-               if (!devl_is_registered(devlink))
-                       goto next_devlink;
+       int idx = 0;
+       int err = 0;
 
-               list_for_each_entry(linecard, &devlink->linecard_list, list) {
-                       if (idx < state->idx) {
-                               idx++;
-                               continue;
-                       }
-                       mutex_lock(&linecard->state_lock);
-                       err = devlink_nl_linecard_fill(msg, devlink, linecard,
-                                                      DEVLINK_CMD_LINECARD_NEW,
-                                                      NETLINK_CB(cb->skb).portid,
-                                                      cb->nlh->nlmsg_seq,
-                                                      NLM_F_MULTI,
-                                                      cb->extack);
-                       mutex_unlock(&linecard->state_lock);
-                       if (err) {
-                               devl_unlock(devlink);
-                               devlink_put(devlink);
-                               state->idx = idx;
-                               goto out;
-                       }
+       list_for_each_entry(linecard, &devlink->linecard_list, list) {
+               if (idx < state->idx) {
                        idx++;
+                       continue;
                }
-next_devlink:
-               devl_unlock(devlink);
-               devlink_put(devlink);
+               mutex_lock(&linecard->state_lock);
+               err = devlink_nl_linecard_fill(msg, devlink, linecard,
+                                              DEVLINK_CMD_LINECARD_NEW,
+                                              NETLINK_CB(cb->skb).portid,
+                                              cb->nlh->nlmsg_seq,
+                                              NLM_F_MULTI,
+                                              cb->extack);
+               mutex_unlock(&linecard->state_lock);
+               if (err) {
+                       state->idx = idx;
+                       break;
+               }
+               idx++;
        }
-out:
-       return msg->len;
+
+       return err;
 }
 
+const struct devlink_gen_cmd devl_gen_linecard = {
+       .dump_one               = devlink_nl_cmd_linecard_get_dump_one,
+};
+
 static struct devlink_linecard_type *
 devlink_linecard_type_lookup(struct devlink_linecard *linecard,
                             const char *type)
@@ -9010,7 +9002,7 @@ const struct genl_small_ops devlink_nl_ops[56] = {
        {
                .cmd = DEVLINK_CMD_LINECARD_GET,
                .doit = devlink_nl_cmd_linecard_get_doit,
-               .dumpit = devlink_nl_cmd_linecard_get_dumpit,
+               .dumpit = devlink_nl_instance_iter_dump,
                .internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD,
                /* can be retrieved by unprivileged users */
        },
index 3f2ab4360f115d7cf4b5e96d56e869924f42128b..b18e216e09b05b626807ee10af09884a6217d147 100644 (file)
@@ -191,6 +191,7 @@ static const struct devlink_gen_cmd *devl_gen_cmds[] = {
        [DEVLINK_CMD_TRAP_GET]          = &devl_gen_trap,
        [DEVLINK_CMD_TRAP_GROUP_GET]    = &devl_gen_trap_group,
        [DEVLINK_CMD_TRAP_POLICER_GET]  = &devl_gen_trap_policer,
+       [DEVLINK_CMD_LINECARD_GET]      = &devl_gen_linecard,
        [DEVLINK_CMD_SELFTESTS_GET]     = &devl_gen_selftests,
 };