275 |
275 |
if not self._enable_locks:
|
276 |
276 |
raise errors.ProgrammerError("Attempted to use disabled locks")
|
277 |
277 |
|
278 |
|
def _AcquireLocks(self, level, names, shared, timeout):
|
|
278 |
def _AcquireLocks(self, level, names, shared, opportunistic, timeout):
|
279 |
279 |
"""Acquires locks via the Ganeti lock manager.
|
280 |
280 |
|
281 |
281 |
@type level: int
|
... | ... | |
284 |
284 |
@param names: Lock names
|
285 |
285 |
@type shared: bool
|
286 |
286 |
@param shared: Whether the locks should be acquired in shared mode
|
|
287 |
@type opportunistic: bool
|
|
288 |
@param opportunistic: Whether to acquire opportunistically
|
287 |
289 |
@type timeout: None or float
|
288 |
290 |
@param timeout: Timeout for acquiring the locks
|
289 |
291 |
@raise LockAcquireTimeout: In case locks couldn't be acquired in specified
|
... | ... | |
298 |
300 |
priority = None
|
299 |
301 |
|
300 |
302 |
acquired = self.context.glm.acquire(level, names, shared=shared,
|
301 |
|
timeout=timeout, priority=priority)
|
|
303 |
timeout=timeout, priority=priority,
|
|
304 |
opportunistic=opportunistic)
|
302 |
305 |
|
303 |
306 |
if acquired is None:
|
304 |
307 |
raise LockAcquireTimeout()
|
... | ... | |
384 |
387 |
|
385 |
388 |
lu.DeclareLocks(level)
|
386 |
389 |
share = lu.share_locks[level]
|
|
390 |
opportunistic = lu.opportunistic_locks[level]
|
387 |
391 |
|
388 |
392 |
try:
|
389 |
393 |
assert adding_locks ^ acquiring_locks, \
|
... | ... | |
393 |
397 |
# Acquiring locks
|
394 |
398 |
needed_locks = lu.needed_locks[level]
|
395 |
399 |
|
396 |
|
self._AcquireLocks(level, needed_locks, share,
|
|
400 |
self._AcquireLocks(level, needed_locks, share, opportunistic,
|
397 |
401 |
calc_timeout())
|
398 |
402 |
else:
|
399 |
403 |
# Adding locks
|
... | ... | |
457 |
461 |
# and in a shared fashion otherwise (to prevent concurrent run with
|
458 |
462 |
# an exclusive LU.
|
459 |
463 |
self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL,
|
460 |
|
not lu_class.REQ_BGL, calc_timeout())
|
|
464 |
not lu_class.REQ_BGL, False, calc_timeout())
|
461 |
465 |
elif lu_class.REQ_BGL:
|
462 |
466 |
raise errors.ProgrammerError("Opcode '%s' requires BGL, but locks are"
|
463 |
467 |
" disabled" % op.OP_ID)
|