From cf4722337fa6045b2faa1efc9f8bda31a2c0d841 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Thu, 11 Sep 2008 09:44:46 +0000 Subject: [PATCH] Parallelize LURemoveInstance Using the new add/remove infrastructure this becomes pretty easy! :) Reviewed-by: imsnah --- lib/cmdlib.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 6636d9c97..81ecc0566 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2481,6 +2481,16 @@ class LURemoveInstance(LogicalUnit): HPATH = "instance-remove" HTYPE = constants.HTYPE_INSTANCE _OP_REQP = ["instance_name", "ignore_failures"] + REQ_BGL = False + + def ExpandNames(self): + self._ExpandAndLockInstance() + self.needed_locks[locking.LEVEL_NODE] = [] + self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE + + def DeclareLocks(self, level): + if level == locking.LEVEL_NODE: + self._LockInstancesNodes() def BuildHooksEnv(self): """Build hooks env. @@ -2498,12 +2508,9 @@ class LURemoveInstance(LogicalUnit): This checks that the instance is in the cluster. """ - instance = self.cfg.GetInstanceInfo( - self.cfg.ExpandInstanceName(self.op.instance_name)) - if instance is None: - raise errors.OpPrereqError("Instance '%s' not known" % - self.op.instance_name) - self.instance = instance + self.instance = self.cfg.GetInstanceInfo(self.op.instance_name) + assert self.instance is not None, \ + "Cannot retrieve locked instance %s" % self.op.instance_name def Exec(self, feedback_fn): """Remove the instance. @@ -2531,8 +2538,7 @@ class LURemoveInstance(LogicalUnit): logger.Info("removing instance %s out of cluster config" % instance.name) self.cfg.RemoveInstance(instance.name) - # Remove the new instance from the Ganeti Lock Manager - self.context.glm.remove(locking.LEVEL_INSTANCE, instance.name) + self.remove_locks[locking.LEVEL_INSTANCE] = instance.name class LUQueryInstances(NoHooksLU): -- GitLab