From fb8dcb621e42b7b44c48573a89d17795081fb3db Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Wed, 30 Jul 2008 11:29:51 +0000 Subject: [PATCH] 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 --- lib/cmdlib.py | 18 ++++++++++++++++++ lib/mcpu.py | 3 +++ 2 files changed, 21 insertions(+) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 243a4c906..4d172eefc 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -150,6 +150,24 @@ class LogicalUnit(object): else: 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. diff --git a/lib/mcpu.py b/lib/mcpu.py index 3cd507914..66f657d48 100644 --- a/lib/mcpu.py +++ b/lib/mcpu.py @@ -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. + lu.DeclareLocks(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, -- GitLab