Revision 0fa753ba lib/mcpu.py
b/lib/mcpu.py | ||
---|---|---|
176 | 176 |
"""Object which runs OpCodes""" |
177 | 177 |
DISPATCH_TABLE = _ComputeDispatchTable() |
178 | 178 |
|
179 |
def __init__(self, context, ec_id): |
|
179 |
def __init__(self, context, ec_id, enable_locks=True):
|
|
180 | 180 |
"""Constructor for Processor |
181 | 181 |
|
182 | 182 |
@type context: GanetiContext |
... | ... | |
190 | 190 |
self._cbs = None |
191 | 191 |
self.rpc = rpc.RpcRunner(context.cfg) |
192 | 192 |
self.hmclass = HooksMaster |
193 |
self._enable_locks = enable_locks |
|
194 |
|
|
195 |
def _CheckLocksEnabled(self): |
|
196 |
"""Checks if locking is enabled. |
|
197 |
|
|
198 |
@raise errors.ProgrammerError: In case locking is not enabled |
|
199 |
|
|
200 |
""" |
|
201 |
if not self._enable_locks: |
|
202 |
raise errors.ProgrammerError("Attempted to use disabled locks") |
|
193 | 203 |
|
194 | 204 |
def _AcquireLocks(self, level, names, shared, timeout, priority): |
195 | 205 |
"""Acquires locks via the Ganeti lock manager. |
... | ... | |
206 | 216 |
amount of time |
207 | 217 |
|
208 | 218 |
""" |
219 |
self._CheckLocksEnabled() |
|
220 |
|
|
209 | 221 |
if self._cbs: |
210 | 222 |
self._cbs.CheckCancel() |
211 | 223 |
|
... | ... | |
291 | 303 |
" others") |
292 | 304 |
|
293 | 305 |
elif adding_locks or acquiring_locks: |
306 |
self._CheckLocksEnabled() |
|
307 |
|
|
294 | 308 |
lu.DeclareLocks(level) |
295 | 309 |
share = lu.share_locks[level] |
296 | 310 |
|
... | ... | |
361 | 375 |
|
362 | 376 |
self._cbs = cbs |
363 | 377 |
try: |
364 |
# Acquire the Big Ganeti Lock exclusively if this LU requires it, |
|
365 |
# and in a shared fashion otherwise (to prevent concurrent run with |
|
366 |
# an exclusive LU. |
|
367 |
self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL, |
|
368 |
not lu_class.REQ_BGL, calc_timeout(), |
|
369 |
priority) |
|
378 |
if self._enable_locks: |
|
379 |
# Acquire the Big Ganeti Lock exclusively if this LU requires it, |
|
380 |
# and in a shared fashion otherwise (to prevent concurrent run with |
|
381 |
# an exclusive LU. |
|
382 |
self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL, |
|
383 |
not lu_class.REQ_BGL, calc_timeout(), |
|
384 |
priority) |
|
385 |
elif lu_class.REQ_BGL: |
|
386 |
raise errors.ProgrammerError("Opcode '%s' requires BGL, but locks are" |
|
387 |
" disabled" % op.OP_ID) |
|
388 |
|
|
370 | 389 |
try: |
371 | 390 |
lu = lu_class(self, op, self.context, self.rpc) |
372 | 391 |
lu.ExpandNames() |
... | ... | |
379 | 398 |
if self._ec_id: |
380 | 399 |
self.context.cfg.DropECReservations(self._ec_id) |
381 | 400 |
finally: |
382 |
self.context.glm.release(locking.LEVEL_CLUSTER) |
|
401 |
# Release BGL if owned |
|
402 |
if self.context.glm.is_owned(locking.LEVEL_CLUSTER): |
|
403 |
assert self._enable_locks |
|
404 |
self.context.glm.release(locking.LEVEL_CLUSTER) |
|
383 | 405 |
finally: |
384 | 406 |
self._cbs = None |
385 | 407 |
|
Also available in: Unified diff