mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 22:05:19 +00:00
netdev-linux: Cache error code from mtu ioctl.
netdev linux devices uses mtu ioctl to get and set MTU for a device. By caching error code from ioctl we can reduce number of ioctl calls for device which is unregistered from system. netdev notification is used to update mtu which saves get-mtu-ioctl. Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
This commit is contained in:
@@ -376,6 +376,8 @@ struct netdev_dev_linux {
|
||||
uint32_t kbits_burst;
|
||||
int vport_stats_error; /* Cached error code from vport_get_stats().
|
||||
0 or an errno value. */
|
||||
int netdev_mtu_error; /* Cached error code from SIOCGIFMTU or SIOCSIFMTU. */
|
||||
|
||||
struct ethtool_drvinfo drvinfo; /* Cached from ETHTOOL_GDRVINFO. */
|
||||
struct tc *tc;
|
||||
|
||||
@@ -532,6 +534,13 @@ netdev_dev_linux_update(struct netdev_dev_linux *dev,
|
||||
if (change->nlmsg_type == RTM_NEWLINK) {
|
||||
/* Keep drv-info */
|
||||
netdev_dev_linux_changed(dev, change->ifi_flags, VALID_DRVINFO);
|
||||
|
||||
if (change->mtu) {
|
||||
dev->mtu = change->mtu;
|
||||
dev->cache_valid |= VALID_MTU;
|
||||
dev->netdev_mtu_error = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
netdev_dev_linux_changed(dev, change->ifi_flags, 0);
|
||||
}
|
||||
@@ -1046,14 +1055,16 @@ netdev_linux_get_mtu(const struct netdev *netdev_, int *mtup)
|
||||
|
||||
error = netdev_linux_do_ioctl(netdev_get_name(netdev_), &ifr,
|
||||
SIOCGIFMTU, "SIOCGIFMTU");
|
||||
if (error) {
|
||||
return error;
|
||||
}
|
||||
|
||||
netdev_dev->netdev_mtu_error = error;
|
||||
netdev_dev->mtu = ifr.ifr_mtu;
|
||||
netdev_dev->cache_valid |= VALID_MTU;
|
||||
}
|
||||
*mtup = netdev_dev->mtu;
|
||||
return 0;
|
||||
|
||||
if (!netdev_dev->netdev_mtu_error) {
|
||||
*mtup = netdev_dev->mtu;
|
||||
}
|
||||
return netdev_dev->netdev_mtu_error;
|
||||
}
|
||||
|
||||
/* Sets the maximum size of transmitted (MTU) for given device using linux
|
||||
@@ -1067,20 +1078,24 @@ netdev_linux_set_mtu(const struct netdev *netdev_, int mtu)
|
||||
struct ifreq ifr;
|
||||
int error;
|
||||
|
||||
if (netdev_dev->cache_valid & VALID_MTU &&
|
||||
netdev_dev->mtu == mtu) {
|
||||
return 0;
|
||||
if (netdev_dev->cache_valid & VALID_MTU) {
|
||||
if (netdev_dev->netdev_mtu_error) {
|
||||
return netdev_dev->netdev_mtu_error;
|
||||
}
|
||||
if (netdev_dev->mtu == mtu) {
|
||||
return 0;
|
||||
}
|
||||
netdev_dev->cache_valid &= ~VALID_MTU;
|
||||
}
|
||||
ifr.ifr_mtu = mtu;
|
||||
error = netdev_linux_do_ioctl(netdev_get_name(netdev_), &ifr,
|
||||
SIOCSIFMTU, "SIOCSIFMTU");
|
||||
if (error) {
|
||||
return error;
|
||||
if (!error || error == ENODEV) {
|
||||
netdev_dev->netdev_mtu_error = error;
|
||||
netdev_dev->mtu = ifr.ifr_mtu;
|
||||
netdev_dev->cache_valid |= VALID_MTU;
|
||||
}
|
||||
|
||||
netdev_dev->mtu = ifr.ifr_mtu;
|
||||
netdev_dev->cache_valid |= VALID_MTU;
|
||||
return 0;
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Returns the ifindex of 'netdev', if successful, as a positive number.
|
||||
|
Reference in New Issue
Block a user