Commit 4c32a8bd authored by Luca Bigliardi's avatar Luca Bigliardi
Browse files

Mlockall: decrease warnings if ctypes module is not present

Node daemon prints a lot of warnings if --no-mlock option is not specified and
ctypes module is not present.

With the following patch the warning is printed only at noded startup.
Signed-off-by: default avatarLuca Bigliardi <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 0d422065
......@@ -845,8 +845,12 @@ def ExecNoded(options, _):
if options.mlock:
request_executor_class = MlockallRequestExecutor
except errors.NoCtypesError:
logging.warning("Cannot set memory lock, ctypes module not found")
request_executor_class = http.server.HttpServerRequestExecutor
request_executor_class = http.server.HttpServerRequestExecutor
......@@ -336,6 +336,12 @@ class UdpDataSizeError(GenericError):
class NoCtypesError(GenericError):
"""python ctypes module is not found in the system.
# errors should be added above
......@@ -1772,18 +1772,19 @@ def CloseFDs(noclose_fds=None):
def Mlockall():
def Mlockall(_ctypes=ctypes):
"""Lock current process' virtual address space into RAM.
This is equivalent to the C call mlockall(MCL_CURRENT|MCL_FUTURE),
see mlock(2) for more details. This function requires ctypes module.
@raises errors.NoCtypesError: if ctypes module is not found
if ctypes is None:
logging.warning("Cannot set memory lock, ctypes module not found")
if _ctypes is None:
raise errors.NoCtypesError()
libc = ctypes.cdll.LoadLibrary("")
libc = _ctypes.cdll.LoadLibrary("")
if libc is None:
logging.error("Cannot set memory lock, ctypes cannot load libc")
......@@ -1794,7 +1795,7 @@ def Mlockall():
# its value correctly, should the mlockall call fail, in order to see what
# the actual error code was.
# pylint: disable-msg=W0212
libc.__errno_location.restype = ctypes.POINTER(ctypes.c_int)
libc.__errno_location.restype = _ctypes.POINTER(_ctypes.c_int)
if libc.mlockall(_MCL_CURRENT | _MCL_FUTURE):
# pylint: disable-msg=W0212
......@@ -28,13 +28,28 @@ This test is run in a separate process because it changes memory behaviour.
import unittest
from ganeti import utils
from ganeti import errors
import testutils
class TestResetTempfileModule(unittest.TestCase):
class TestMlockallWithCtypes(unittest.TestCase):
"""Whether Mlockall() works if ctypes is present.
def test(self):
if utils.ctypes:
class TestMlockallWithNoCtypes(unittest.TestCase):
"""Whether Mlockall() raises an error if ctypes is not present.
def test(self):
self.assertRaises(errors.NoCtypesError, utils.Mlockall, _ctypes=None)
if __name__ == "__main__":
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