Revision dc4bdf73

b/lib/mcpu.py
246 246
  """Object which runs OpCodes"""
247 247
  DISPATCH_TABLE = _ComputeDispatchTable()
248 248

  
249
  def __init__(self, context, ec_id):
249
  def __init__(self, context, ec_id, enable_locks=True):
250 250
    """Constructor for Processor
251 251

  
252 252
    @type context: GanetiContext
......
260 260
    self._cbs = None
261 261
    self.rpc = context.rpc
262 262
    self.hmclass = HooksMaster
263
    self._enable_locks = enable_locks
264

  
265
  def _CheckLocksEnabled(self):
266
    """Checks if locking is enabled.
267

  
268
    @raise errors.ProgrammerError: In case locking is not enabled
269

  
270
    """
271
    if not self._enable_locks:
272
      raise errors.ProgrammerError("Attempted to use disabled locks")
263 273

  
264 274
  def _AcquireLocks(self, level, names, shared, timeout, priority):
265 275
    """Acquires locks via the Ganeti lock manager.
......
276 286
        amount of time
277 287

  
278 288
    """
289
    self._CheckLocksEnabled()
290

  
279 291
    if self._cbs:
280 292
      self._cbs.CheckCancel()
281 293

  
......
350 362
                                " others")
351 363

  
352 364
    elif adding_locks or acquiring_locks:
365
      self._CheckLocksEnabled()
366

  
353 367
      lu.DeclareLocks(level)
354 368
      share = lu.share_locks[level]
355 369

  
......
420 434

  
421 435
    self._cbs = cbs
422 436
    try:
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
      self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL,
427
                          not lu_class.REQ_BGL, calc_timeout(),
428
                          priority)
437
      if self._enable_locks:
438
        # Acquire the Big Ganeti Lock exclusively if this LU requires it,
439
        # and in a shared fashion otherwise (to prevent concurrent run with
440
        # an exclusive LU.
441
        self._AcquireLocks(locking.LEVEL_CLUSTER, locking.BGL,
442
                            not lu_class.REQ_BGL, calc_timeout(),
443
                            priority)
444
      elif lu_class.REQ_BGL:
445
        raise errors.ProgrammerError("Opcode '%s' requires BGL, but locks are"
446
                                     " disabled" % op.OP_ID)
447

  
429 448
      try:
430 449
        lu = lu_class(self, op, self.context, self.rpc)
431 450
        lu.ExpandNames()
......
438 457
          if self._ec_id:
439 458
            self.context.cfg.DropECReservations(self._ec_id)
440 459
      finally:
441
        self.context.glm.release(locking.LEVEL_CLUSTER)
460
        # Release BGL if owned
461
        if self.context.glm.is_owned(locking.LEVEL_CLUSTER):
462
          assert self._enable_locks
463
          self.context.glm.release(locking.LEVEL_CLUSTER)
442 464
    finally:
443 465
      self._cbs = None
444 466

  
b/lib/server/masterd.py
427 427

  
428 428
    """
429 429
    # Queries don't have a job id
430
    proc = mcpu.Processor(self.server.context, None)
430
    proc = mcpu.Processor(self.server.context, None, enable_locks=False)
431 431

  
432 432
    # TODO: Executing an opcode using locks will acquire them in blocking mode.
433 433
    # Consider using a timeout for retries.

Also available in: Unified diff