diff --git a/lib/jqueue.py b/lib/jqueue.py index 6bc02a2706e6c986549fd4380ce4c0c5d2922de6..d96094ea8d56aa1920e126e36ede00748e7c7648 100644 --- a/lib/jqueue.py +++ b/lib/jqueue.py @@ -28,6 +28,7 @@ from ganeti import constants from ganeti import workerpool from ganeti import errors from ganeti import mcpu +from ganeti import utils JOBQUEUE_THREADS = 5 diff --git a/lib/utils.py b/lib/utils.py index 5e4233a053f8304573944b0a69790a1692a7325c..33bf83f3be51f9c19913db3f43693babdf42f86b 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -1063,3 +1063,22 @@ def CheckVolumeGroupSize(vglist, vgname, minsize): return ("volume group '%s' too small (%s MiB required, %d MiB found)" % (vgname, minsize, vgsize)) return None + + +def LockedMethod(fn): + """Synchronized object access decorator. + + This decorator is intended to protect access to an object using the + object's own lock which is hardcoded to '_lock'. + + """ + def wrapper(self, *args, **kwargs): + assert hasattr(self, '_lock') + lock = self._lock + lock.acquire() + try: + result = fn(self, *args, **kwargs) + finally: + lock.release() + return result + return wrapper