Revision 4c32a8bd
b/daemons/ganeti-noded | ||
---|---|---|
845 | 845 |
|
846 | 846 |
""" |
847 | 847 |
if options.mlock: |
848 |
utils.Mlockall() |
|
849 | 848 |
request_executor_class = MlockallRequestExecutor |
849 |
try: |
|
850 |
utils.Mlockall() |
|
851 |
except errors.NoCtypesError: |
|
852 |
logging.warning("Cannot set memory lock, ctypes module not found") |
|
853 |
request_executor_class = http.server.HttpServerRequestExecutor |
|
850 | 854 |
else: |
851 | 855 |
request_executor_class = http.server.HttpServerRequestExecutor |
852 | 856 |
|
b/lib/errors.py | ||
---|---|---|
336 | 336 |
""" |
337 | 337 |
|
338 | 338 |
|
339 |
class NoCtypesError(GenericError): |
|
340 |
"""python ctypes module is not found in the system. |
|
341 |
|
|
342 |
""" |
|
343 |
|
|
344 |
|
|
339 | 345 |
# errors should be added above |
340 | 346 |
|
341 | 347 |
|
b/lib/utils.py | ||
---|---|---|
1772 | 1772 |
_CloseFDNoErr(fd) |
1773 | 1773 |
|
1774 | 1774 |
|
1775 |
def Mlockall(): |
|
1775 |
def Mlockall(_ctypes=ctypes):
|
|
1776 | 1776 |
"""Lock current process' virtual address space into RAM. |
1777 | 1777 |
|
1778 | 1778 |
This is equivalent to the C call mlockall(MCL_CURRENT|MCL_FUTURE), |
1779 | 1779 |
see mlock(2) for more details. This function requires ctypes module. |
1780 | 1780 |
|
1781 |
@raises errors.NoCtypesError: if ctypes module is not found |
|
1782 |
|
|
1781 | 1783 |
""" |
1782 |
if ctypes is None: |
|
1783 |
logging.warning("Cannot set memory lock, ctypes module not found") |
|
1784 |
return |
|
1784 |
if _ctypes is None: |
|
1785 |
raise errors.NoCtypesError() |
|
1785 | 1786 |
|
1786 |
libc = ctypes.cdll.LoadLibrary("libc.so.6") |
|
1787 |
libc = _ctypes.cdll.LoadLibrary("libc.so.6")
|
|
1787 | 1788 |
if libc is None: |
1788 | 1789 |
logging.error("Cannot set memory lock, ctypes cannot load libc") |
1789 | 1790 |
return |
... | ... | |
1794 | 1795 |
# its value correctly, should the mlockall call fail, in order to see what |
1795 | 1796 |
# the actual error code was. |
1796 | 1797 |
# pylint: disable-msg=W0212 |
1797 |
libc.__errno_location.restype = ctypes.POINTER(ctypes.c_int)
|
|
1798 |
libc.__errno_location.restype = _ctypes.POINTER(_ctypes.c_int)
|
|
1798 | 1799 |
|
1799 | 1800 |
if libc.mlockall(_MCL_CURRENT | _MCL_FUTURE): |
1800 | 1801 |
# pylint: disable-msg=W0212 |
b/test/ganeti.utils_mlockall_unittest.py | ||
---|---|---|
28 | 28 |
import unittest |
29 | 29 |
|
30 | 30 |
from ganeti import utils |
31 |
from ganeti import errors |
|
31 | 32 |
|
32 | 33 |
import testutils |
33 | 34 |
|
34 | 35 |
|
35 |
class TestResetTempfileModule(unittest.TestCase): |
|
36 |
class TestMlockallWithCtypes(unittest.TestCase): |
|
37 |
"""Whether Mlockall() works if ctypes is present. |
|
38 |
|
|
39 |
""" |
|
40 |
|
|
41 |
def test(self): |
|
42 |
if utils.ctypes: |
|
43 |
utils.Mlockall() |
|
44 |
|
|
45 |
|
|
46 |
class TestMlockallWithNoCtypes(unittest.TestCase): |
|
47 |
"""Whether Mlockall() raises an error if ctypes is not present. |
|
48 |
|
|
49 |
""" |
|
50 |
|
|
36 | 51 |
def test(self): |
37 |
utils.Mlockall()
|
|
52 |
self.assertRaises(errors.NoCtypesError, utils.Mlockall, _ctypes=None)
|
|
38 | 53 |
|
39 | 54 |
|
40 | 55 |
if __name__ == "__main__": |
Also available in: Unified diff