When creating instances, we can only choose from those nodes where we have both, the NODE and the NODE_RES lock. So, when opportunistically allocating locks, at the level of NODE_RES, there is no point in considering more nodes than those we have the node lock for. This change not only avoids acquiring locks we cannot use, it also make the opportunistic minimal lock requirement more useful.
Signed-off-by: Klaus Aehlig <[email protected]> --- lib/cmdlib/instance_create.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/cmdlib/instance_create.py b/lib/cmdlib/instance_create.py index c6e83eb..e32e55f 100644 --- a/lib/cmdlib/instance_create.py +++ b/lib/cmdlib/instance_create.py @@ -429,6 +429,12 @@ class LUInstanceCreate(LogicalUnit): self.needed_locks[locking.LEVEL_NODE])) self.share_locks[locking.LEVEL_NODEGROUP] = 1 + def DeclareLocks(self, level): + if level == locking.LEVEL_NODE_RES: + if self.op.opportunistic_locking: + self.needed_locks[locking.LEVEL_NODE_RES] = \ + CopyLockList(list(self.owned_locks(locking.LEVEL_NODE))) + def _RunAllocator(self): """Run the allocator based on input opcode. -- 2.2.0.rc0.207.ga3a616c
