]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
devlink: Add pr_out_dev() helper function
authorMoshe Shemesh <moshe@mellanox.com>
Mon, 7 Dec 2020 05:35:21 +0000 (07:35 +0200)
committerDavid Ahern <dsahern@gmail.com>
Wed, 9 Dec 2020 02:42:09 +0000 (02:42 +0000)
Add pr_out_dev() helper function and use it both by cmd_dev_show_cb()
and by cmd_mon_show_cb().

Dev stats will be added on the next patch to dev context, so
cmd_mon_show_cb() should print the whole dev context and not just dev
handle.

Signed-off-by: Moshe Shemesh <moshe@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
devlink/devlink.c

index 6b30f6245ee83d5689d48017d4961fed4f004d7e..f16fc801f4015135a8146148950430e87c072932 100644 (file)
@@ -2975,17 +2975,11 @@ static int cmd_dev_param(struct dl *dl)
        pr_err("Command \"%s\" not found\n", dl_argv(dl));
        return -ENOENT;
 }
-static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
+
+static void pr_out_dev(struct dl *dl, struct nlattr **tb)
 {
-       struct dl *dl = data;
-       struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
-       struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
        uint8_t reload_failed = 0;
 
-       mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
-       if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
-               return MNL_CB_ERROR;
-
        if (tb[DEVLINK_ATTR_RELOAD_FAILED])
                reload_failed = mnl_attr_get_u8(tb[DEVLINK_ATTR_RELOAD_FAILED]);
 
@@ -2997,7 +2991,19 @@ static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
        } else {
                pr_out_handle(dl, tb);
        }
+}
 
+static int cmd_dev_show_cb(const struct nlmsghdr *nlh, void *data)
+{
+       struct dl *dl = data;
+       struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+       struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
+
+       mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb);
+       if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
+               return MNL_CB_ERROR;
+
+       pr_out_dev(dl, tb);
        return MNL_CB_OK;
 }
 
@@ -4843,7 +4849,7 @@ static int cmd_mon_show_cb(const struct nlmsghdr *nlh, void *data)
                if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME])
                        return MNL_CB_ERROR;
                pr_out_mon_header(genl->cmd);
-               pr_out_handle(dl, tb);
+               pr_out_dev(dl, tb);
                pr_out_mon_footer();
                break;
        case DEVLINK_CMD_PORT_GET: /* fall through */