Commit 271fee18 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Helga Velroyen
Browse files

Implement network locking in Instance queries



This is needed in case more info than each nic's network uuid is to
be returned. We need to lock networks to get valid data. For now
only the name is returned as an extra field. All other can be added
with trivial effort.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Reviewed-by: default avatarHelga Velroyen <helgav@google.com>
parent f98e1175
......@@ -5751,6 +5751,7 @@ class _InstanceQuery(_QueryBase):
lu.needed_locks[locking.LEVEL_INSTANCE] = self.wanted
lu.needed_locks[locking.LEVEL_NODEGROUP] = []
lu.needed_locks[locking.LEVEL_NODE] = []
lu.needed_locks[locking.LEVEL_NETWORK] = []
lu.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
 
self.do_grouplocks = (self.do_locking and
......@@ -5770,6 +5771,12 @@ class _InstanceQuery(_QueryBase):
elif level == locking.LEVEL_NODE:
lu._LockInstancesNodes() # pylint: disable=W0212
 
elif level == locking.LEVEL_NETWORK:
lu.needed_locks[locking.LEVEL_NETWORK] = \
frozenset(net_uuid
for instance_name in lu.owned_locks(locking.LEVEL_INSTANCE)
for net_uuid in lu.cfg.GetInstanceNetworks(instance_name))
@staticmethod
def _CheckGroupLocks(lu):
owned_instances = frozenset(lu.owned_locks(locking.LEVEL_INSTANCE))
......@@ -12823,12 +12830,13 @@ class LUInstanceQueryData(NoHooksLU):
 
self.needed_locks[locking.LEVEL_NODEGROUP] = []
self.needed_locks[locking.LEVEL_NODE] = []
self.needed_locks[locking.LEVEL_NETWORK] = []
self.recalculate_locks[locking.LEVEL_NODE] = constants.LOCKS_REPLACE
 
def DeclareLocks(self, level):
if self.op.use_locking:
owned_instances = self.owned_locks(locking.LEVEL_INSTANCE)
if level == locking.LEVEL_NODEGROUP:
owned_instances = self.owned_locks(locking.LEVEL_INSTANCE)
 
# Lock all groups used by instances optimistically; this requires going
# via the node before it's locked, requiring verification later on
......@@ -12841,6 +12849,13 @@ class LUInstanceQueryData(NoHooksLU):
elif level == locking.LEVEL_NODE:
self._LockInstancesNodes()
 
elif level == locking.LEVEL_NETWORK:
self.needed_locks[locking.LEVEL_NETWORK] = \
frozenset(net_uuid
for instance_name in owned_instances
for net_uuid in
self.cfg.GetInstanceNetworks(instance_name))
def CheckPrereq(self):
"""Check prerequisites.
 
......@@ -12850,6 +12865,7 @@ class LUInstanceQueryData(NoHooksLU):
owned_instances = frozenset(self.owned_locks(locking.LEVEL_INSTANCE))
owned_groups = frozenset(self.owned_locks(locking.LEVEL_NODEGROUP))
owned_nodes = frozenset(self.owned_locks(locking.LEVEL_NODE))
owned_networks = frozenset(self.owned_locks(locking.LEVEL_NETWORK))
 
if self.wanted_names is None:
assert self.op.use_locking, "Locking was not used"
......@@ -12861,7 +12877,8 @@ class LUInstanceQueryData(NoHooksLU):
_CheckInstancesNodeGroups(self.cfg, instances, owned_groups, owned_nodes,
None)
else:
assert not (owned_instances or owned_groups or owned_nodes)
assert not (owned_instances or owned_groups or
owned_nodes or owned_networks)
 
self.wanted_instances = instances.values()
 
......@@ -12945,7 +12962,6 @@ class LUInstanceQueryData(NoHooksLU):
for node in nodes.values()))
 
group2name_fn = lambda uuid: groups[uuid].name
for instance in self.wanted_instances:
pnode = nodes[instance.primary_node]
 
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment