Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp618649pxu; Sun, 22 Nov 2020 22:23:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxzdxHk1juF3B/xgU+mDqPd4hcRWhkh8A9qMcRG85094E3WOpufq9TasQ3PJsKKOMOCqdJ+ X-Received: by 2002:a17:906:1408:: with SMTP id p8mr41945065ejc.548.1606112637167; Sun, 22 Nov 2020 22:23:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606112637; cv=none; d=google.com; s=arc-20160816; b=EGzEPdKBEpPtS3yQl753zjk4CUNb7CtZPCkHzSCk3gTQOww9GwXMRUibCEvwI5Qskz OQ/zJa07Aj0K9mKYTetnUrAROgjsRUezfo3MiMDMrNoii5/EAlUJFckxU7r/yLedB56f axR7pZXd/P7uRvU4GpF/3kbQVjqmv1DQxMY+L1txifiCd06895rqGAVBzeUTHW2fQisM Pcm7ZiaNMSFwAm0xYHB2GvFOb50bvh5KgxuOf+YjqyKSr+Oq99vIrmefRLqBIkwun61O VtB1iEVd3PaaVXh7EAxiVjIayA2vY+70gc8Mq92Ov46EGlPPIRbvkx9ZO2lBwMk2siKX StdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=AZoa1V9qMtn1OggQhnYLkoynPBqNssYg0Dc1MF++sas=; b=XIEtd3s9neFP3gsCy0PW2p1fBNv2RYCR0inN58h5gH1wrzbmnpGw7ESCZPxdfGP/wu 4r0Us0wNT6NKfH+URB8T4Y5CDxMuK6m0P5gCh12b2kWxB8e0Ly8X8CRpptoCJvuTZ7Zr IEqE3cicLQhxDhmR+LiU1PcUMlXzwfbePTpQAs9nt7EwATodeHLCPUWZcBnr2t2VDYLJ jdL5Nw3leQaslj1S5hJBD+8iSqMdZ7JYjK6o5WlMEngN05ebZ5IKtpqciFDa94chDaEM /OWGymgx7o2xdYYjvgbMFGVPrlMqKLCDSsJevfkW44p3QYXLSsaW1HaYwe5BMbjX+4Wy m0SQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h12si6850897ejx.340.2020.11.22.22.23.34; Sun, 22 Nov 2020 22:23:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727088AbgKWFgv (ORCPT + 99 others); Mon, 23 Nov 2020 00:36:51 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:36269 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726163AbgKWFgu (ORCPT ); Mon, 23 Nov 2020 00:36:50 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from moshe@mellanox.com) with SMTP; 23 Nov 2020 07:36:43 +0200 Received: from vnc1.mtl.labs.mlnx (vnc1.mtl.labs.mlnx [10.7.2.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 0AN5ahTA000721; Mon, 23 Nov 2020 07:36:43 +0200 Received: from vnc1.mtl.labs.mlnx (localhost [127.0.0.1]) by vnc1.mtl.labs.mlnx (8.14.4/8.14.4) with ESMTP id 0AN5ahth025283; Mon, 23 Nov 2020 07:36:43 +0200 Received: (from moshe@localhost) by vnc1.mtl.labs.mlnx (8.14.4/8.14.4/Submit) id 0AN5abhC025268; Mon, 23 Nov 2020 07:36:37 +0200 From: Moshe Shemesh To: "David S. Miller" , Jakub Kicinski Cc: Jiri Pirko , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Moshe Shemesh Subject: [PATCH net v2] devlink: Fix reload stats structure Date: Mon, 23 Nov 2020 07:36:25 +0200 Message-Id: <1606109785-25197-1-git-send-email-moshe@mellanox.com> X-Mailer: git-send-email 1.8.4.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: a254c264267e ("devlink: Add reload stats") Signed-off-by: Moshe Shemesh Reviewed-by: Jiri Pirko --- v1 -> v2: - Fold comment at 80 characters. --- include/uapi/linux/devlink.h | 2 ++ net/core/devlink.c | 49 +++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 0113bc4db9f5..5203f54a2be1 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -526,6 +526,8 @@ enum devlink_attr { DEVLINK_ATTR_RELOAD_STATS_LIMIT, /* u8 */ DEVLINK_ATTR_RELOAD_STATS_VALUE, /* u32 */ DEVLINK_ATTR_REMOTE_RELOAD_STATS, /* nested */ + DEVLINK_ATTR_RELOAD_ACTION_INFO, /* nested */ + DEVLINK_ATTR_RELOAD_ACTION_STATS, /* nested */ /* add new attributes above here, update the policy in devlink.c */ diff --git a/net/core/devlink.c b/net/core/devlink.c index e6fb1fdedded..bf79d018990c 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -517,8 +517,7 @@ devlink_reload_limit_is_supported(struct devlink *devlink, enum devlink_reload_l return test_bit(limit, &devlink->ops->reload_limits); } -static int devlink_reload_stat_put(struct sk_buff *msg, enum devlink_reload_action action, - enum devlink_reload_limit limit, u32 value) +static int devlink_reload_stat_put(struct sk_buff *msg, enum devlink_reload_limit limit, u32 value) { struct nlattr *reload_stats_entry; @@ -526,8 +525,7 @@ static int devlink_reload_stat_put(struct sk_buff *msg, enum devlink_reload_acti if (!reload_stats_entry) return -EMSGSIZE; - if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_ACTION, action) || - nla_put_u8(msg, DEVLINK_ATTR_RELOAD_STATS_LIMIT, limit) || + if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_STATS_LIMIT, limit) || nla_put_u32(msg, DEVLINK_ATTR_RELOAD_STATS_VALUE, value)) goto nla_put_failure; nla_nest_end(msg, reload_stats_entry); @@ -540,7 +538,7 @@ static int devlink_reload_stat_put(struct sk_buff *msg, enum devlink_reload_acti static int devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink, bool is_remote) { - struct nlattr *reload_stats_attr; + struct nlattr *reload_stats_attr, *action_info_attr, *action_stats_attr; int i, j, stat_idx; u32 value; @@ -552,17 +550,28 @@ static int devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink if (!reload_stats_attr) return -EMSGSIZE; - for (j = 0; j <= DEVLINK_RELOAD_LIMIT_MAX; j++) { - /* Remote stats are shown even if not locally supported. Stats - * of actions with unspecified limit are shown though drivers - * don't need to register unspecified limit. - */ - if (!is_remote && j != DEVLINK_RELOAD_LIMIT_UNSPEC && - !devlink_reload_limit_is_supported(devlink, j)) + for (i = 0; i <= DEVLINK_RELOAD_ACTION_MAX; i++) { + if ((!is_remote && !devlink_reload_action_is_supported(devlink, i)) || + i == DEVLINK_RELOAD_ACTION_UNSPEC) continue; - for (i = 0; i <= DEVLINK_RELOAD_ACTION_MAX; i++) { - if ((!is_remote && !devlink_reload_action_is_supported(devlink, i)) || - i == DEVLINK_RELOAD_ACTION_UNSPEC || + action_info_attr = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_ACTION_INFO); + if (!action_info_attr) + goto nla_put_failure; + + if (nla_put_u8(msg, DEVLINK_ATTR_RELOAD_ACTION, i)) + goto action_info_nest_cancel; + action_stats_attr = nla_nest_start(msg, DEVLINK_ATTR_RELOAD_ACTION_STATS); + if (!action_stats_attr) + goto action_info_nest_cancel; + + for (j = 0; j <= DEVLINK_RELOAD_LIMIT_MAX; j++) { + /* Remote stats are shown even if not locally supported. + * Stats of actions with unspecified limit are shown + * though drivers don't need to register unspecified + * limit. + */ + if ((!is_remote && j != DEVLINK_RELOAD_LIMIT_UNSPEC && + !devlink_reload_limit_is_supported(devlink, j)) || devlink_reload_combination_is_invalid(i, j)) continue; @@ -571,13 +580,19 @@ static int devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink value = devlink->stats.reload_stats[stat_idx]; else value = devlink->stats.remote_reload_stats[stat_idx]; - if (devlink_reload_stat_put(msg, i, j, value)) - goto nla_put_failure; + if (devlink_reload_stat_put(msg, j, value)) + goto action_stats_nest_cancel; } + nla_nest_end(msg, action_stats_attr); + nla_nest_end(msg, action_info_attr); } nla_nest_end(msg, reload_stats_attr); return 0; +action_stats_nest_cancel: + nla_nest_cancel(msg, action_stats_attr); +action_info_nest_cancel: + nla_nest_cancel(msg, action_info_attr); nla_put_failure: nla_nest_cancel(msg, reload_stats_attr); return -EMSGSIZE; -- 2.18.2