Commit fb8dcb62 authored by Guido Trotter's avatar Guido Trotter
Browse files

Add LogicalUnit.DeclareLocks

This additional LogicalUnit function is optional to implement, but lets
you change your locking needs for one level just before locking it, but
after the previous levels have been already locked. It is useful for
example to calculate what nodes to lock after locking an instance.

Reviewed-by: iustinp
parent 74b5913f
......@@ -150,6 +150,24 @@ class LogicalUnit(object):
raise NotImplementedError
def DeclareLocks(self, level):
"""Declare LU locking needs for a level
While most LUs can just declare their locking needs at ExpandNames time,
sometimes there's the need to calculate some locks after having acquired
the ones before. This function is called just before acquiring locks at a
particular level, but after acquiring the ones at lower levels, and permits
such calculations. It can be used to modify self.needed_locks, and by
default it does nothing.
This function is only called if you have something already set in
self.needed_locks for the level.
@param level: Locking level which is going to be locked
@type level: member of ganeti.locking.LEVELS
def CheckPrereq(self):
"""Check prerequisites for this LU.
......@@ -131,6 +131,9 @@ class Processor(object):
if level in lu.needed_locks:
# This gives a chance to LUs to make last-minute changes after acquiring
# locks at any preceding level.
# This is always safe to do, as we can't acquire more/less locks than
# what was requested.
lu.needed_locks[level] = self.context.glm.acquire(level,
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment