Revision 211b6132 lib/mcpu.py
b/lib/mcpu.py | ||
---|---|---|
221 | 221 |
self.rpc = rpc.RpcRunner(context.cfg) |
222 | 222 |
self.hmclass = HooksMaster |
223 | 223 |
|
224 |
def _ReportLocks(self, level, names, shared, acquired):
|
|
224 |
def _ReportLocks(self, level, names, shared, timeout, acquired, result):
|
|
225 | 225 |
"""Reports lock operations. |
226 | 226 |
|
227 | 227 |
@type level: int |
... | ... | |
229 | 229 |
@type names: list or string |
230 | 230 |
@param names: Lock names |
231 | 231 |
@type shared: bool |
232 |
@param shared: Whether the lock should be acquired in shared mode |
|
232 |
@param shared: Whether the locks should be acquired in shared mode |
|
233 |
@type timeout: None or float |
|
234 |
@param timeout: Timeout for acquiring the locks |
|
233 | 235 |
@type acquired: bool |
234 |
@param acquired: Whether the lock has already been acquired |
|
236 |
@param acquired: Whether the locks have already been acquired |
|
237 |
@type result: None or set |
|
238 |
@param result: Result from L{locking.GanetiLockManager.acquire} |
|
235 | 239 |
|
236 | 240 |
""" |
237 | 241 |
parts = [] |
238 | 242 |
|
239 | 243 |
# Build message |
240 | 244 |
if acquired: |
241 |
parts.append("acquired") |
|
245 |
if result is None: |
|
246 |
parts.append("timeout") |
|
247 |
else: |
|
248 |
parts.append("acquired") |
|
242 | 249 |
else: |
243 | 250 |
parts.append("waiting") |
251 |
if timeout is None: |
|
252 |
parts.append("blocking") |
|
253 |
else: |
|
254 |
parts.append("timeout=%0.6fs" % timeout) |
|
244 | 255 |
|
245 | 256 |
parts.append(locking.LEVEL_NAMES[level]) |
246 | 257 |
|
... | ... | |
263 | 274 |
if self._cbs: |
264 | 275 |
self._cbs.ReportLocks(msg) |
265 | 276 |
|
277 |
def _AcquireLocks(self, level, names, shared, timeout): |
|
278 |
"""Acquires locks via the Ganeti lock manager. |
|
279 |
|
|
280 |
@type level: int |
|
281 |
@param level: Lock level |
|
282 |
@type names: list or string |
|
283 |
@param names: Lock names |
|
284 |
@type shared: bool |
|
285 |
@param shared: Whether the locks should be acquired in shared mode |
|
286 |
@type timeout: None or float |
|
287 |
@param timeout: Timeout for acquiring the locks |
|
288 |
|
|
289 |
""" |
|
290 |
self._ReportLocks(level, names, shared, timeout, False, None) |
|
291 |
|
|
292 |
acquired = self.context.glm.acquire(level, names, shared=shared, |
|
293 |
timeout=timeout) |
|
294 |
|
|
295 |
self._ReportLocks(level, names, shared, timeout, True, acquired) |
|
296 |
|
|
297 |
return acquired |
|
298 |
|
|
266 | 299 |
def _ExecLU(self, lu): |
267 | 300 |
"""Logical Unit execution sequence. |
268 | 301 |
|
... | ... | |
328 | 361 |
# Acquiring locks |
329 | 362 |
needed_locks = lu.needed_locks[level] |
330 | 363 |
|
331 |
self._ReportLocks(level, needed_locks, share, False) |
|
332 |
acquired = self.context.glm.acquire(level, |
|
333 |
needed_locks, |
|
334 |
shared=share, |
|
335 |
timeout=calc_timeout()) |
|
336 |
# TODO: Report timeout |
|
337 |
self._ReportLocks(level, needed_locks, share, True) |
|
364 |
acquired = self._AcquireLocks(level, needed_locks, share, |
|
365 |
calc_timeout()) |
|
338 | 366 |
|
339 | 367 |
if acquired is None: |
340 | 368 |
raise _LockAcquireTimeout() |
... | ... | |
392 | 420 |
|
393 | 421 |
while True: |
394 | 422 |
try: |
395 |
self._ReportLocks(locking.LEVEL_CLUSTER, [locking.BGL], |
|
396 |
not lu_class.REQ_BGL, False) |
|
397 |
try: |
|
398 |
# Acquire the Big Ganeti Lock exclusively if this LU requires it, |
|
399 |
# and in a shared fashion otherwise (to prevent concurrent run with |
|
400 |
# an exclusive LU. |
|
401 |
acquired_bgl = self.context.glm.acquire(locking.LEVEL_CLUSTER, |
|
402 |
[locking.BGL], |
|
403 |
shared=not lu_class.REQ_BGL, |
|
404 |
timeout=calc_timeout()) |
|
405 |
finally: |
|
406 |
# TODO: Report timeout |
|
407 |
self._ReportLocks(locking.LEVEL_CLUSTER, [locking.BGL], |
|
408 |
not lu_class.REQ_BGL, True) |
|
409 |
|
|
410 |
if acquired_bgl is None: |
|
423 |
# Acquire the Big Ganeti Lock exclusively if this LU requires it, |
|
424 |
# and in a shared fashion otherwise (to prevent concurrent run with |
|
425 |
# an exclusive LU. |
|
426 |
if self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL, |
|
427 |
not lu_class.REQ_BGL, calc_timeout()) is None: |
|
411 | 428 |
raise _LockAcquireTimeout() |
412 | 429 |
|
413 | 430 |
try: |
Also available in: Unified diff