1
0
mirror of https://github.com/CumulusNetworks/ifupdown2.git synced 2024-05-06 15:54:50 +00:00

SCALE: addressvirtual: replace glob.glob with listdir

using glob.glob is way to costly, use os.listdir to increase
performances.

Test with timeit show the following for 10k loop:
time_glob executed in 39.16788899600215 seconds
time_listdir executed in 5.625843115005409 seconds

Signed-off-by: Julien Fortin <jfortin@nvidia.com>
This commit is contained in:
Julien Fortin
2023-08-03 02:33:15 +02:00
parent f494105031
commit e15c8287cc
2 changed files with 23 additions and 13 deletions

1
debian/changelog vendored
View File

@@ -1,5 +1,6 @@
ifupdown2 (3.2.1) unstable; urgency=medium
* New: performance improvement: replace glob.glob with os.listdir
* New: Attribute: "disable-ipv6" to control ipv6 on an interface
* New: Policy: "default_loopback_scope" control loopback ip scope
* Fix: keep link down after mac change if 'link-down yes' is specified

View File

@@ -274,24 +274,33 @@ class addressvirtual(AddonWithIpBlackList, moduleBase):
return False, None
def _get_macvlan_ifnames(self, ifaceobj):
macvlan_prefixes = (
self._get_macvlan_prefix(ifaceobj),
self.get_vrrp_prefix(ifaceobj.name, "4"),
self.get_vrrp_prefix(ifaceobj.name, "6")
)
ifnames = set()
for f in os.listdir("/sys/class/net/"):
if f.startswith(macvlan_prefixes):
ifnames.add(f)
return ifnames
def _remove_running_address_config(self, ifaceobj):
if not self.cache.link_exists(ifaceobj.name):
return
hwaddress = []
for macvlan_prefix in [
self._get_macvlan_prefix(ifaceobj),
self.get_vrrp_prefix(ifaceobj.name, "4"),
self.get_vrrp_prefix(ifaceobj.name, "6")
]:
for macvlan_ifacename in glob.glob("/sys/class/net/%s*" % macvlan_prefix):
macvlan_ifacename = os.path.basename(macvlan_ifacename)
if not self.cache.link_exists(macvlan_ifacename) or self.cache.get_link_kind(macvlan_ifacename) != "macvlan":
continue
hwaddress.append(self.cache.get_link_address(macvlan_ifacename))
self.netlink.link_del(os.path.basename(macvlan_ifacename))
# XXX: Also delete any fdb addresses. This requires, checking mac address
# on individual macvlan interfaces and deleting the vlan from that.
for macvlan_ifacename in self._get_macvlan_ifnames(ifaceobj):
if not self.cache.link_exists(macvlan_ifacename) or self.cache.get_link_kind(macvlan_ifacename) != "macvlan":
continue
hwaddress.append(self.cache.get_link_address(macvlan_ifacename))
self.netlink.link_del(macvlan_ifacename)
# XXX: Also delete any fdb addresses. This requires, checking mac address
# on individual macvlan interfaces and deleting the vlan from that.
if any(hwaddress):
self._remove_addresses_from_bridge(ifaceobj, hwaddress)