diff mbox series

[iproute2-net,2/3] devlink: Add pr_out_dev() helper function

Message ID 1606389296-3906-3-git-send-email-moshe@mellanox.com
State Superseded
Headers show
Series devlink: Add devlink reload action limit and stats | expand

Commit Message

Moshe Shemesh Nov. 26, 2020, 11:14 a.m. UTC
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>
---
 devlink/devlink.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

Comments

David Ahern Nov. 29, 2020, 9:15 p.m. UTC | #1
On 11/26/20 4:14 AM, Moshe Shemesh wrote:
> diff --git a/devlink/devlink.c b/devlink/devlink.c
> index a9ba0072..bd588869 100644
> --- a/devlink/devlink.c
> +++ b/devlink/devlink.c
> @@ -2974,17 +2974,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)

why 'pr_out_dev'? there is no 'dev' argument.

>  {
> -	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]);
>
Moshe Shemesh Dec. 2, 2020, 7 a.m. UTC | #2
On 11/29/2020 11:15 PM, David Ahern wrote:
> On 11/26/20 4:14 AM, Moshe Shemesh wrote:
>> diff --git a/devlink/devlink.c b/devlink/devlink.c
>> index a9ba0072..bd588869 100644
>> --- a/devlink/devlink.c
>> +++ b/devlink/devlink.c
>> @@ -2974,17 +2974,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)
> why 'pr_out_dev'? there is no 'dev' argument.


Because it prints command dev show output, the data is in tb argument 
and includes bus name, dev name and dev stats.
>>   {
>> -	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]);
>>
diff mbox series

Patch

diff --git a/devlink/devlink.c b/devlink/devlink.c
index a9ba0072..bd588869 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -2974,17 +2974,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]);
 
@@ -2996,7 +2990,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;
 }
 
@@ -4838,7 +4844,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 */