Revision 4b6fa0bf
b/Makefile.am | ||
---|---|---|
340 | 340 |
test/ganeti.ssh_unittest.py \ |
341 | 341 |
test/ganeti.uidpool_unittest.py \ |
342 | 342 |
test/ganeti.utils_unittest.py \ |
343 |
test/ganeti.utils_mlockall_unittest.py \ |
|
343 | 344 |
test/ganeti.workerpool_unittest.py \ |
344 | 345 |
test/docs_unittest.py \ |
345 | 346 |
test/tempfile_fork_unittest.py |
b/lib/utils.py | ||
---|---|---|
57 | 57 |
import sha |
58 | 58 |
sha1 = sha.new |
59 | 59 |
|
60 |
try: |
|
61 |
import ctypes |
|
62 |
except ImportError: |
|
63 |
ctypes = None |
|
64 |
|
|
60 | 65 |
from ganeti import errors |
61 | 66 |
from ganeti import constants |
62 | 67 |
|
... | ... | |
83 | 88 |
_STRUCT_UCRED = "iII" |
84 | 89 |
_STRUCT_UCRED_SIZE = struct.calcsize(_STRUCT_UCRED) |
85 | 90 |
|
91 |
# Flags for mlockall() (from bits/mman.h) |
|
92 |
_MCL_CURRENT = 1 |
|
93 |
_MCL_FUTURE = 2 |
|
94 |
|
|
86 | 95 |
|
87 | 96 |
class RunResult(object): |
88 | 97 |
"""Holds the result of running external programs. |
... | ... | |
1739 | 1748 |
_CloseFDNoErr(fd) |
1740 | 1749 |
|
1741 | 1750 |
|
1751 |
def Mlockall(): |
|
1752 |
"""Lock current process' virtual address space into RAM. |
|
1753 |
|
|
1754 |
This is equivalent to the C call mlockall(MCL_CURRENT|MCL_FUTURE), |
|
1755 |
see mlock(2) for more details. This function requires ctypes module. |
|
1756 |
|
|
1757 |
""" |
|
1758 |
if ctypes is None: |
|
1759 |
logging.warning("Cannot set memory lock, ctypes module not found") |
|
1760 |
return |
|
1761 |
|
|
1762 |
libc = ctypes.cdll.LoadLibrary("libc.so.6") |
|
1763 |
if libc is None: |
|
1764 |
logging.error("Cannot set memory lock, ctypes cannot load libc") |
|
1765 |
return |
|
1766 |
|
|
1767 |
# Some older version of the ctypes module don't have built-in functionality |
|
1768 |
# to access the errno global variable, where function error codes are stored. |
|
1769 |
# By declaring this variable as a pointer to an integer we can then access |
|
1770 |
# its value correctly, should the mlockall call fail, in order to see what |
|
1771 |
# the actual error code was. |
|
1772 |
libc.__errno_location.restype = ctypes.POINTER(ctypes.c_int) |
|
1773 |
|
|
1774 |
if libc.mlockall(_MCL_CURRENT | _MCL_FUTURE): |
|
1775 |
logging.error("Cannot set memory lock: %s" % |
|
1776 |
os.strerror(libc.__errno_location().contents.value)) |
|
1777 |
return |
|
1778 |
|
|
1779 |
logging.debug("Memory lock set") |
|
1780 |
|
|
1781 |
|
|
1742 | 1782 |
def Daemonize(logfile): |
1743 | 1783 |
"""Daemonize the current process. |
1744 | 1784 |
|
b/test/ganeti.utils_mlockall_unittest.py | ||
---|---|---|
1 |
#!/usr/bin/python |
|
2 |
# |
|
3 |
|
|
4 |
# Copyright (C) 2010 Google Inc. |
|
5 |
# |
|
6 |
# This program is free software; you can redistribute it and/or modify |
|
7 |
# it under the terms of the GNU General Public License as published by |
|
8 |
# the Free Software Foundation; either version 2 of the License, or |
|
9 |
# (at your option) any later version. |
|
10 |
# |
|
11 |
# This program is distributed in the hope that it will be useful, but |
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
# General Public License for more details. |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License |
|
17 |
# along with this program; if not, write to the Free Software |
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
19 |
# 02110-1301, USA. |
|
20 |
|
|
21 |
|
|
22 |
"""Script for testing utils.Mlockall |
|
23 |
|
|
24 |
This test is run in a separate process because it changes memory behaviour. |
|
25 |
|
|
26 |
""" |
|
27 |
|
|
28 |
import unittest |
|
29 |
|
|
30 |
from ganeti import utils |
|
31 |
|
|
32 |
import testutils |
|
33 |
|
|
34 |
|
|
35 |
class TestResetTempfileModule(unittest.TestCase): |
|
36 |
def test(self): |
|
37 |
utils.Mlockall() |
|
38 |
|
|
39 |
|
|
40 |
if __name__ == "__main__": |
|
41 |
testutils.GanetiTestProgram() |
Also available in: Unified diff