From 8646adce5b3fb092ec2192d26979dadea6fee286 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Thu, 11 Sep 2008 17:45:26 +0000 Subject: [PATCH] Parallelize Tag operations For now we lock the instance/node for adding/deleting tags from it, but we could probably in the future do without, with more support from the config for atomic operations. Reviewed-by: iustinp --- lib/cmdlib.py | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 23789b360..6dbaa9287 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -4845,26 +4845,34 @@ class TagsLU(NoHooksLU): This is an abstract class which is the parent of all the other tags LUs. """ - def CheckPrereq(self): - """Check prerequisites. - """ - if self.op.kind == constants.TAG_CLUSTER: - self.target = self.cfg.GetClusterInfo() - elif self.op.kind == constants.TAG_NODE: + def ExpandNames(self): + self.needed_locks = {} + if self.op.kind == constants.TAG_NODE: name = self.cfg.ExpandNodeName(self.op.name) if name is None: raise errors.OpPrereqError("Invalid node name (%s)" % (self.op.name,)) self.op.name = name - self.target = self.cfg.GetNodeInfo(name) + self.needed_locks[locking.LEVEL_NODE] = name elif self.op.kind == constants.TAG_INSTANCE: name = self.cfg.ExpandInstanceName(self.op.name) if name is None: raise errors.OpPrereqError("Invalid instance name (%s)" % (self.op.name,)) self.op.name = name - self.target = self.cfg.GetInstanceInfo(name) + self.needed_locks[locking.LEVEL_INSTANCE] = name + + def CheckPrereq(self): + """Check prerequisites. + + """ + if self.op.kind == constants.TAG_CLUSTER: + self.target = self.cfg.GetClusterInfo() + elif self.op.kind == constants.TAG_NODE: + self.target = self.cfg.GetNodeInfo(self.op.name) + elif self.op.kind == constants.TAG_INSTANCE: + self.target = self.cfg.GetInstanceInfo(self.op.name) else: raise errors.OpPrereqError("Wrong tag type requested (%s)" % str(self.op.kind)) @@ -4875,6 +4883,7 @@ class LUGetTags(TagsLU): """ _OP_REQP = ["kind", "name"] + REQ_BGL = False def Exec(self, feedback_fn): """Returns the tag list. @@ -4888,6 +4897,10 @@ class LUSearchTags(NoHooksLU): """ _OP_REQP = ["pattern"] + REQ_BGL = False + + def ExpandNames(self): + self.needed_locks = {} def CheckPrereq(self): """Check prerequisites. @@ -4907,9 +4920,9 @@ class LUSearchTags(NoHooksLU): """ cfg = self.cfg tgts = [("/cluster", cfg.GetClusterInfo())] - ilist = [cfg.GetInstanceInfo(name) for name in cfg.GetInstanceList()] + ilist = cfg.GetAllInstancesInfo().values() tgts.extend([("/instances/%s" % i.name, i) for i in ilist]) - nlist = [cfg.GetNodeInfo(name) for name in cfg.GetNodeList()] + nlist = cfg.GetAllNodesInfo().values() tgts.extend([("/nodes/%s" % n.name, n) for n in nlist]) results = [] for path, target in tgts: @@ -4924,6 +4937,7 @@ class LUAddTags(TagsLU): """ _OP_REQP = ["kind", "name", "tags"] + REQ_BGL = False def CheckPrereq(self): """Check prerequisites. @@ -4957,6 +4971,7 @@ class LUDelTags(TagsLU): """ _OP_REQP = ["kind", "name", "tags"] + REQ_BGL = False def CheckPrereq(self): """Check prerequisites. -- GitLab