Improve LUQueryNodes for lockless case
authorIustin Pop <iustin@google.com>
Mon, 14 Dec 2009 15:26:48 +0000 (16:26 +0100)
committerIustin Pop <iustin@google.com>
Mon, 14 Dec 2009 15:34:13 +0000 (16:34 +0100)
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 <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>

lib/cmdlib.py

index 3914435..87ce76d 100644 (file)
@@ -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: