From 4dfd62661512563329e80bd5600714fab4e4f41f Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 14 Dec 2009 16:26:48 +0100 Subject: [PATCH] Improve LUQueryNodes for lockless case In most uses of LUQueryNodes, we don't take a lock. This means that the instance data is not protected across GetInstanceList and GetInstanceInfo, and this can lead to instances not existing anymore. Switching to GetAllInstanceInfo means that we get a single, semi-consistent snapshot (since instances can still be modified, but it's much better). Signed-off-by: Iustin Pop Reviewed-by: Michael Hanselmann --- lib/cmdlib.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 3914435..87ce76d 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -2083,10 +2083,9 @@ class LUQueryNodes(NoHooksLU): inst_fields = frozenset(("pinst_cnt", "pinst_list", "sinst_cnt", "sinst_list")) if inst_fields & frozenset(self.op.output_fields): - instancelist = self.cfg.GetInstanceList() + inst_data = self.cfg.GetAllInstancesInfo() - for instance_name in instancelist: - inst = self.cfg.GetInstanceInfo(instance_name) + for instance_name, inst in inst_data.items(): if inst.primary_node in node_to_primary: node_to_primary[inst.primary_node].add(inst.name) for secnode in inst.secondary_nodes: -- 1.7.10.4