public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Edwin Peer <edwin.peer@broadcom•com>
To: netdev@vger•kernel.org
Cc: Edwin Peer <edwin.peer@broadcom•com>,
	Jakub Kicinski <kuba@kernel•org>,
	Andrew Gospodarek <andrew.gospodarek@broadcom•com>,
	Michael Chan <michael.chan@broadcom•com>,
	Stephen Hemminger <stephen@networkplumber•org>,
	Michal Kubecek <mkubecek@suse•cz>,
	David Ahern <dsahern@gmail•com>
Subject: [PATCH net-next 3/4] rtnetlink: refactor IFLA_VF_INFO stats into rtnl_fill_vfstats()
Date: Fri, 22 Jan 2021 20:53:20 -0800	[thread overview]
Message-ID: <20210123045321.2797360-4-edwin.peer@broadcom.com> (raw)
In-Reply-To: <20210123045321.2797360-1-edwin.peer@broadcom.com>

[-- Attachment #1: Type: text/plain, Size: 4104 bytes --]

Moving VF stats into their own function will facilitate separating
them out later.

No functional change.

Signed-off-by: Edwin Peer <edwin.peer@broadcom•com>
---
 net/core/rtnetlink.c | 66 +++++++++++++++++++++++++-------------------
 1 file changed, 38 insertions(+), 28 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 466f920ac974..95564fd12f24 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1223,6 +1223,42 @@ static noinline_for_stack int rtnl_fill_stats(struct sk_buff *skb,
 	return 0;
 }
 
+static noinline_for_stack int rtnl_fill_vfstats(struct sk_buff *skb,
+						struct net_device *dev,
+						int vf_num)
+{
+	struct ifla_vf_stats vf_stats;
+	struct nlattr *vfstats;
+
+	memset(&vf_stats, 0, sizeof(vf_stats));
+	if (dev->netdev_ops->ndo_get_vf_stats)
+		dev->netdev_ops->ndo_get_vf_stats(dev, vf_num, &vf_stats);
+	vfstats = nla_nest_start_noflag(skb, IFLA_VF_STATS);
+	if (!vfstats)
+		return -EMSGSIZE;
+	if (nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_PACKETS,
+			      vf_stats.rx_packets, IFLA_VF_STATS_PAD) ||
+	    nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_PACKETS,
+			      vf_stats.tx_packets, IFLA_VF_STATS_PAD) ||
+	    nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_BYTES,
+			      vf_stats.rx_bytes, IFLA_VF_STATS_PAD) ||
+	    nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_BYTES,
+			      vf_stats.tx_bytes, IFLA_VF_STATS_PAD) ||
+	    nla_put_u64_64bit(skb, IFLA_VF_STATS_BROADCAST,
+			      vf_stats.broadcast, IFLA_VF_STATS_PAD) ||
+	    nla_put_u64_64bit(skb, IFLA_VF_STATS_MULTICAST,
+			      vf_stats.multicast, IFLA_VF_STATS_PAD) ||
+	    nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_DROPPED,
+			      vf_stats.rx_dropped, IFLA_VF_STATS_PAD) ||
+	    nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_DROPPED,
+			      vf_stats.tx_dropped, IFLA_VF_STATS_PAD)) {
+		nla_nest_cancel(skb, vfstats);
+		return -EMSGSIZE;
+	}
+	nla_nest_end(skb, vfstats);
+	return 0;
+}
+
 static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
 					       struct net_device *dev,
 					       int vfs_num,
@@ -1230,12 +1266,11 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
 					       u32 ext_filter_mask)
 {
 	struct ifla_vf_rss_query_en vf_rss_query_en;
-	struct nlattr *vf, *vfstats, *vfvlanlist;
+	struct nlattr *vf, *vfvlanlist;
 	struct ifla_vf_link_state vf_linkstate;
 	struct ifla_vf_vlan_info vf_vlan_info;
 	struct ifla_vf_spoofchk vf_spoofchk;
 	struct ifla_vf_tx_rate vf_tx_rate;
-	struct ifla_vf_stats vf_stats;
 	struct ifla_vf_trust vf_trust;
 	struct ifla_vf_vlan vf_vlan;
 	struct ifla_vf_rate vf_rate;
@@ -1334,33 +1369,8 @@ static noinline_for_stack int rtnl_fill_vfinfo(struct sk_buff *skb,
 	}
 	nla_nest_end(skb, vfvlanlist);
 	if (~ext_filter_mask & RTEXT_FILTER_SKIP_STATS) {
-		memset(&vf_stats, 0, sizeof(vf_stats));
-		if (dev->netdev_ops->ndo_get_vf_stats)
-			dev->netdev_ops->ndo_get_vf_stats(dev, vfs_num,
-							  &vf_stats);
-		vfstats = nla_nest_start_noflag(skb, IFLA_VF_STATS);
-		if (!vfstats)
-			goto nla_put_vf_failure;
-		if (nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_PACKETS,
-				      vf_stats.rx_packets, IFLA_VF_STATS_PAD) ||
-		    nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_PACKETS,
-				      vf_stats.tx_packets, IFLA_VF_STATS_PAD) ||
-		    nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_BYTES,
-				      vf_stats.rx_bytes, IFLA_VF_STATS_PAD) ||
-		    nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_BYTES,
-				      vf_stats.tx_bytes, IFLA_VF_STATS_PAD) ||
-		    nla_put_u64_64bit(skb, IFLA_VF_STATS_BROADCAST,
-				      vf_stats.broadcast, IFLA_VF_STATS_PAD) ||
-		    nla_put_u64_64bit(skb, IFLA_VF_STATS_MULTICAST,
-				      vf_stats.multicast, IFLA_VF_STATS_PAD) ||
-		    nla_put_u64_64bit(skb, IFLA_VF_STATS_RX_DROPPED,
-				      vf_stats.rx_dropped, IFLA_VF_STATS_PAD) ||
-		    nla_put_u64_64bit(skb, IFLA_VF_STATS_TX_DROPPED,
-				      vf_stats.tx_dropped, IFLA_VF_STATS_PAD)) {
-			nla_nest_cancel(skb, vfstats);
+		if (rtnl_fill_vfstats(skb, dev, vfs_num))
 			goto nla_put_vf_failure;
-		}
-		nla_nest_end(skb, vfstats);
 	}
 	nla_nest_end(skb, vf);
 	return 0;
-- 
2.30.0


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4160 bytes --]

  parent reply	other threads:[~2021-01-23  4:54 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-23  4:53 [PATCH net-next 0/4] support for 256 VFs in RTM_GETLINK Edwin Peer
2021-01-23  4:53 ` [PATCH net-next 1/4] netlink: truncate overlength attribute list in nla_nest_end() Edwin Peer
2021-01-23 19:14   ` David Ahern
2021-01-23 20:42     ` Edwin Peer
2021-01-23 21:03       ` Edwin Peer
2021-01-26  4:56         ` David Ahern
2021-01-26 17:51           ` Edwin Peer
2023-06-05  7:28             ` Gal Pressman
2023-06-05 18:58               ` Jakub Kicinski
2023-06-05 19:27                 ` Edwin Peer
2023-06-06  8:01                   ` Gal Pressman
2023-06-06 16:17                     ` Jakub Kicinski
2023-06-07 13:31                       ` Gal Pressman
2023-06-07 16:33                         ` Jakub Kicinski
2023-06-07 16:52                           ` Stephen Hemminger
2023-06-07 17:29                             ` Jakub Kicinski
2021-01-26  4:50       ` David Ahern
2021-01-26  1:43   ` Jakub Kicinski
2021-01-23  4:53 ` [PATCH net-next 2/4] rtnetlink: extend RTEXT_FILTER_SKIP_STATS to IFLA_VF_INFO Edwin Peer
2021-01-26  1:55   ` Jakub Kicinski
2021-01-26 22:48     ` Edwin Peer
2021-01-23  4:53 ` Edwin Peer [this message]
2021-01-23  4:53 ` [PATCH net-next 4/4] rtnetlink: promote IFLA_VF_STATS to same level as IFLA_VF_INFO Edwin Peer
2021-01-26  2:01   ` Jakub Kicinski
2021-01-26 14:50     ` Edwin Peer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210123045321.2797360-4-edwin.peer@broadcom.com \
    --to=edwin.peer@broadcom$(echo .)com \
    --cc=andrew.gospodarek@broadcom$(echo .)com \
    --cc=dsahern@gmail$(echo .)com \
    --cc=kuba@kernel$(echo .)org \
    --cc=michael.chan@broadcom$(echo .)com \
    --cc=mkubecek@suse$(echo .)cz \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=stephen@networkplumber$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox