Commit f6e0fb81 authored by Petr Machata's avatar Petr Machata Committed by David S. Miller

net: rtnetlink: Stop assuming that IFLA_OFFLOAD_XSTATS_* are dev-backed

The IFLA_STATS_LINK_OFFLOAD_XSTATS attribute is a nest whose child
attributes carry various special hardware statistics. The code that handles
this nest was written with the idea that all these statistics would be
exposed by the device driver of a physical netdevice.

In the following patches, a new attribute is added to the abovementioned
nest, which however can be defined for some soft netdevices. The NDO-based
approach to querying these does not work, because it is not the soft
netdevice driver that exposes these statistics, but an offloading NIC
driver that does so.

The current code does not scale well to this usage. Simply rewrite it back
to the pattern seen in other fill-like and get_size-like functions
elsewhere.

Extract to helpers the code that is concerned with handling specifically
NDO-backed statistics so that it can be easily reused should more such
statistics be added.
Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6b524a1d
...@@ -5048,84 +5048,81 @@ static bool stats_attr_valid(unsigned int mask, int attrid, int idxattr) ...@@ -5048,84 +5048,81 @@ static bool stats_attr_valid(unsigned int mask, int attrid, int idxattr)
(!idxattr || idxattr == attrid); (!idxattr || idxattr == attrid);
} }
#define IFLA_OFFLOAD_XSTATS_FIRST (IFLA_OFFLOAD_XSTATS_UNSPEC + 1) static bool
static int rtnl_get_offload_stats_attr_size(int attr_id) rtnl_offload_xstats_have_ndo(const struct net_device *dev, int attr_id)
{ {
switch (attr_id) { return dev->netdev_ops &&
case IFLA_OFFLOAD_XSTATS_CPU_HIT: dev->netdev_ops->ndo_has_offload_stats &&
return sizeof(struct rtnl_link_stats64); dev->netdev_ops->ndo_get_offload_stats &&
} dev->netdev_ops->ndo_has_offload_stats(dev, attr_id);
}
return 0; static unsigned int
rtnl_offload_xstats_get_size_ndo(const struct net_device *dev, int attr_id)
{
return rtnl_offload_xstats_have_ndo(dev, attr_id) ?
sizeof(struct rtnl_link_stats64) : 0;
} }
static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev, static int
int *prividx) rtnl_offload_xstats_fill_ndo(struct net_device *dev, int attr_id,
struct sk_buff *skb)
{ {
unsigned int size = rtnl_offload_xstats_get_size_ndo(dev, attr_id);
struct nlattr *attr = NULL; struct nlattr *attr = NULL;
int attr_id, size;
void *attr_data; void *attr_data;
int err; int err;
if (!(dev->netdev_ops && dev->netdev_ops->ndo_has_offload_stats && if (!size)
dev->netdev_ops->ndo_get_offload_stats))
return -ENODATA; return -ENODATA;
for (attr_id = IFLA_OFFLOAD_XSTATS_FIRST; attr = nla_reserve_64bit(skb, attr_id, size,
attr_id <= IFLA_OFFLOAD_XSTATS_MAX; attr_id++) { IFLA_OFFLOAD_XSTATS_UNSPEC);
if (attr_id < *prividx) if (!attr)
continue; return -EMSGSIZE;
size = rtnl_get_offload_stats_attr_size(attr_id); attr_data = nla_data(attr);
if (!size) memset(attr_data, 0, size);
continue;
if (!dev->netdev_ops->ndo_has_offload_stats(dev, attr_id)) err = dev->netdev_ops->ndo_get_offload_stats(attr_id, dev, attr_data);
continue; if (err)
return err;
attr = nla_reserve_64bit(skb, attr_id, size, return 0;
IFLA_OFFLOAD_XSTATS_UNSPEC); }
if (!attr)
goto nla_put_failure;
attr_data = nla_data(attr); static int rtnl_offload_xstats_fill(struct sk_buff *skb, struct net_device *dev,
memset(attr_data, 0, size); int *prividx)
err = dev->netdev_ops->ndo_get_offload_stats(attr_id, dev, {
attr_data); int attr_id_cpu_hit = IFLA_OFFLOAD_XSTATS_CPU_HIT;
if (err) bool have_data = false;
goto get_offload_stats_failure; int err;
if (*prividx <= attr_id_cpu_hit) {
err = rtnl_offload_xstats_fill_ndo(dev, attr_id_cpu_hit, skb);
if (!err) {
have_data = true;
} else if (err != -ENODATA) {
*prividx = attr_id_cpu_hit;
return err;
}
} }
if (!attr) if (!have_data)
return -ENODATA; return -ENODATA;
*prividx = 0; *prividx = 0;
return 0; return 0;
nla_put_failure:
err = -EMSGSIZE;
get_offload_stats_failure:
*prividx = attr_id;
return err;
} }
static int rtnl_offload_xstats_get_size(const struct net_device *dev) static int rtnl_offload_xstats_get_size(const struct net_device *dev)
{ {
int attr_id_cpu_hit = IFLA_OFFLOAD_XSTATS_CPU_HIT;
int nla_size = 0; int nla_size = 0;
int attr_id;
int size; int size;
if (!(dev->netdev_ops && dev->netdev_ops->ndo_has_offload_stats && size = rtnl_offload_xstats_get_size_ndo(dev, attr_id_cpu_hit);
dev->netdev_ops->ndo_get_offload_stats)) nla_size += nla_total_size_64bit(size);
return 0;
for (attr_id = IFLA_OFFLOAD_XSTATS_FIRST;
attr_id <= IFLA_OFFLOAD_XSTATS_MAX; attr_id++) {
if (!dev->netdev_ops->ndo_has_offload_stats(dev, attr_id))
continue;
size = rtnl_get_offload_stats_attr_size(attr_id);
nla_size += nla_total_size_64bit(size);
}
if (nla_size != 0) if (nla_size != 0)
nla_size += nla_total_size(0); nla_size += nla_total_size(0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment