Skip to content

Commit 5204bb6

Browse files
Moshe Shemeshkuba-moo
authored andcommitted
devlink: Fix reload stats structure
Fix reload stats structure exposed to the user. Change stats structure hierarchy to have the reload action as a parent of the stat entry and then stat entry includes value per limit. This will also help to avoid string concatenation on iproute2 output. Reload stats structure before this fix: "stats": { "reload": { "driver_reinit": 2, "fw_activate": 1, "fw_activate_no_reset": 0 } } After this fix: "stats": { "reload": { "driver_reinit": { "unspecified": 2 }, "fw_activate": { "unspecified": 1, "no_reset": 0 } } Fixes: a254c26 ("devlink: Add reload stats") Signed-off-by: Moshe Shemesh <[email protected]> Reviewed-by: Jiri Pirko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9bd2702 commit 5204bb6

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

include/uapi/linux/devlink.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ enum devlink_attr {
526526
DEVLINK_ATTR_RELOAD_STATS_LIMIT, /* u8 */
527527
DEVLINK_ATTR_RELOAD_STATS_VALUE, /* u32 */
528528
DEVLINK_ATTR_REMOTE_RELOAD_STATS, /* nested */
529+
DEVLINK_ATTR_RELOAD_ACTION_INFO, /* nested */
530+
DEVLINK_ATTR_RELOAD_ACTION_STATS, /* nested */
529531

530532
/* add new attributes above here, update the policy in devlink.c */
531533

net/core/devlink.c

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ devlink_reload_limit_is_supported(struct devlink *devlink, enum devlink_reload_l
517517
return test_bit(limit, &devlink->ops->reload_limits);
518518
}
519519

520-
static int devlink_reload_stat_put(struct sk_buff *msg, enum devlink_reload_action action,
520+
static int devlink_reload_stat_put(struct sk_buff *msg,
521521
enum devlink_reload_limit limit, u32 value)
522522
{
523523
struct nlattr *reload_stats_entry;
@@ -526,8 +526,7 @@ static int devlink_reload_stat_put(struct sk_buff *msg, enum devlink_reload_acti
526526
if (!reload_stats_entry)
527527
return -EMSGSIZE;
528528

529-
if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_ACTION, action) ||
530-
nla_put_u8(msg, DEVLINK_ATTR_RELOAD_STATS_LIMIT, limit) ||
529+
if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_STATS_LIMIT, limit) ||
531530
nla_put_u32(msg, DEVLINK_ATTR_RELOAD_STATS_VALUE, value))
532531
goto nla_put_failure;
533532
nla_nest_end(msg, reload_stats_entry);
@@ -540,7 +539,7 @@ static int devlink_reload_stat_put(struct sk_buff *msg, enum devlink_reload_acti
540539

541540
static int devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink, bool is_remote)
542541
{
543-
struct nlattr *reload_stats_attr;
542+
struct nlattr *reload_stats_attr, *act_info, *act_stats;
544543
int i, j, stat_idx;
545544
u32 value;
546545

@@ -552,17 +551,29 @@ static int devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink
552551
if (!reload_stats_attr)
553552
return -EMSGSIZE;
554553

555-
for (j = 0; j <= DEVLINK_RELOAD_LIMIT_MAX; j++) {
556-
/* Remote stats are shown even if not locally supported. Stats
557-
* of actions with unspecified limit are shown though drivers
558-
* don't need to register unspecified limit.
559-
*/
560-
if (!is_remote && j != DEVLINK_RELOAD_LIMIT_UNSPEC &&
561-
!devlink_reload_limit_is_supported(devlink, j))
554+
for (i = 0; i <= DEVLINK_RELOAD_ACTION_MAX; i++) {
555+
if ((!is_remote &&
556+
!devlink_reload_action_is_supported(devlink, i)) ||
557+
i == DEVLINK_RELOAD_ACTION_UNSPEC)
562558
continue;
563-
for (i = 0; i <= DEVLINK_RELOAD_ACTION_MAX; i++) {
564-
if ((!is_remote && !devlink_reload_action_is_supported(devlink, i)) ||
565-
i == DEVLINK_RELOAD_ACTION_UNSPEC ||
559+
act_info = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_ACTION_INFO);
560+
if (!act_info)
561+
goto nla_put_failure;
562+
563+
if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_ACTION, i))
564+
goto action_info_nest_cancel;
565+
act_stats = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_ACTION_STATS);
566+
if (!act_stats)
567+
goto action_info_nest_cancel;
568+
569+
for (j = 0; j <= DEVLINK_RELOAD_LIMIT_MAX; j++) {
570+
/* Remote stats are shown even if not locally supported.
571+
* Stats of actions with unspecified limit are shown
572+
* though drivers don't need to register unspecified
573+
* limit.
574+
*/
575+
if ((!is_remote && j != DEVLINK_RELOAD_LIMIT_UNSPEC &&
576+
!devlink_reload_limit_is_supported(devlink, j)) ||
566577
devlink_reload_combination_is_invalid(i, j))
567578
continue;
568579

@@ -571,13 +582,19 @@ static int devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink
571582
value = devlink->stats.reload_stats[stat_idx];
572583
else
573584
value = devlink->stats.remote_reload_stats[stat_idx];
574-
if (devlink_reload_stat_put(msg, i, j, value))
575-
goto nla_put_failure;
585+
if (devlink_reload_stat_put(msg, j, value))
586+
goto action_stats_nest_cancel;
576587
}
588+
nla_nest_end(msg, act_stats);
589+
nla_nest_end(msg, act_info);
577590
}
578591
nla_nest_end(msg, reload_stats_attr);
579592
return 0;
580593

594+
action_stats_nest_cancel:
595+
nla_nest_cancel(msg, act_stats);
596+
action_info_nest_cancel:
597+
nla_nest_cancel(msg, act_info);
581598
nla_put_failure:
582599
nla_nest_cancel(msg, reload_stats_attr);
583600
return -EMSGSIZE;

0 commit comments

Comments
 (0)