]> git.proxmox.com Git - mirror_ifupdown2.git/commit - ifupdown2/addons/vrf.py
performance fix: better handling fd to allow subprocess.close_fds=False and code...
authorJulien Fortin <julien@cumulusnetworks.com>
Fri, 13 May 2016 17:52:57 +0000 (19:52 +0200)
committerJulien Fortin <julien@cumulusnetworks.com>
Thu, 16 Jun 2016 02:37:33 +0000 (03:37 +0100)
commita193d8d1c041d1199031052e83b5f62bc127edbd
tree053f3b32bde56986a86dc1569cdb51a3c34beab8
parentafe51251638ae91766c82edc299812c09b7da636
performance fix: better handling fd to allow subprocess.close_fds=False and code re-organisation

Ticket: None
Reviewed By: CCR-4692
Testing Done: smoke + scale tests

If called with close_fds=True the subprocess module will try to close every fd
from 3 to MAXFD before executing the specified command. This is done in Python
not even with a C-implementation which truly affecting performances.

This patch aims to better handle the file descriptor used by ifupdown2. Either
by closing them after use or by setting the close-on-exec flag for the file
descriptor, which causes the file descriptor to be automatically
(and atomically) closed when any of the exec-family functions succeed.

With the actual patch all tests are passing, I can't think of any future issue
but if any a possible future modification might be to use the parameter
'preexec_fn', which allows us to set function which will be executed in the
child process before executing the command line. We can always manually close
any remaining open file descriptors with something like:

>>> os.listdir('/proc/self/fd/')
['0', '1', '2', ‘3’, etc..]
>>> for fd in os.listdir('/proc/self/fd/')
>>>    if int(fd) > 2:
>>>       os.close(fd)

This patch is also totally re-organising the use of subprocesses. By removing
all subprocess code redundancy.
18 files changed:
addons/ethtool.py
addons/usercmds.py
addons/vrf.py
addons/vrrpd.py
ifupdown/ifupdownbase.py
ifupdown/networkinterfaces.py
ifupdown/policymanager.py
ifupdown/scheduler.py
ifupdown/utils.py
ifupdownaddons/bondutil.py
ifupdownaddons/bridgeutils.py
ifupdownaddons/dhclient.py
ifupdownaddons/iproute2.py
ifupdownaddons/modulebase.py
ifupdownaddons/mstpctlutil.py
ifupdownaddons/systemutils.py
ifupdownaddons/utilsbase.py
sbin/ifupdown2