Commit f22433c0 authored by Dimitris Aragiorgis's avatar Dimitris Aragiorgis Committed by Michael Hanselmann
Browse files

Locking related fixes for networks



Use GetNetwork() only when having already aquired the lock,
i.e. in CheckPrereq().

In LUNetworkConnect/Disconnect do not include Network info in Hooks
environment, so that network locking can be avoided if conflicts
are not checked.

Invoke _CheckNodeGroupInstances() only in case of conflicts check,
because otherwise owned instances are None, which results to an error.
Signed-off-by: default avatarDimitris Aragiorgis <dimara@grnet.gr>
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 3516b09a
...@@ -15778,7 +15778,8 @@ class LUNetworkRemove(LogicalUnit): ...@@ -15778,7 +15778,8 @@ class LUNetworkRemove(LogicalUnit):
self.network_uuid = self.cfg.LookupNetwork(self.op.network_name) self.network_uuid = self.cfg.LookupNetwork(self.op.network_name)
   
if not self.network_uuid: if not self.network_uuid:
raise errors.OpPrereqError("Network %s not found" % self.op.network_name, raise errors.OpPrereqError(("Network '%s' not found" %
self.op.network_name),
errors.ECODE_INVAL) errors.ECODE_INVAL)
   
self.share_locks[locking.LEVEL_NODEGROUP] = 1 self.share_locks[locking.LEVEL_NODEGROUP] = 1
...@@ -15795,19 +15796,17 @@ class LUNetworkRemove(LogicalUnit): ...@@ -15795,19 +15796,17 @@ class LUNetworkRemove(LogicalUnit):
cluster. cluster.
   
""" """
# Verify that the network is not conncted. # Verify that the network is not conncted.
node_groups = [group.name node_groups = [group.name
for group in self.cfg.GetAllNodeGroupsInfo().values() for group in self.cfg.GetAllNodeGroupsInfo().values()
for net in group.networks.keys() if self.network_uuid in group.networks]
if net == self.network_uuid]
   
if node_groups: if node_groups:
self.LogWarning("Nework '%s' is connected to the following" self.LogWarning("Network '%s' is connected to the following"
" node groups: %s" % (self.op.network_name, " node groups: %s" %
utils.CommaJoin(utils.NiceSort(node_groups)))) (self.op.network_name,
raise errors.OpPrereqError("Network still connected", utils.CommaJoin(utils.NiceSort(node_groups))))
errors.ECODE_STATE) raise errors.OpPrereqError("Network still connected", errors.ECODE_STATE)
   
def BuildHooksEnv(self): def BuildHooksEnv(self):
"""Build hooks env. """Build hooks env.
...@@ -15851,11 +15850,11 @@ class LUNetworkSetParams(LogicalUnit): ...@@ -15851,11 +15850,11 @@ class LUNetworkSetParams(LogicalUnit):
   
def ExpandNames(self): def ExpandNames(self):
self.network_uuid = self.cfg.LookupNetwork(self.op.network_name) self.network_uuid = self.cfg.LookupNetwork(self.op.network_name)
self.network = self.cfg.GetNetwork(self.network_uuid) if self.network_uuid is None:
if self.network is None: raise errors.OpPrereqError(("Network '%s' not found" %
raise errors.OpPrereqError("Could not retrieve network '%s' (UUID: %s)" % self.op.network_name),
(self.op.network_name, self.network_uuid),
errors.ECODE_INVAL) errors.ECODE_INVAL)
self.needed_locks = { self.needed_locks = {
locking.LEVEL_NETWORK: [self.network_uuid], locking.LEVEL_NETWORK: [self.network_uuid],
} }
...@@ -15864,6 +15863,7 @@ class LUNetworkSetParams(LogicalUnit): ...@@ -15864,6 +15863,7 @@ class LUNetworkSetParams(LogicalUnit):
"""Check prerequisites. """Check prerequisites.
   
""" """
self.network = self.cfg.GetNetwork(self.network_uuid)
self.gateway = self.network.gateway self.gateway = self.network.gateway
self.network_type = self.network.network_type self.network_type = self.network.network_type
self.mac_prefix = self.network.mac_prefix self.mac_prefix = self.network.mac_prefix
...@@ -16115,22 +16115,24 @@ class LUNetworkConnect(LogicalUnit): ...@@ -16115,22 +16115,24 @@ class LUNetworkConnect(LogicalUnit):
self.network_link = self.op.network_link self.network_link = self.op.network_link
   
self.network_uuid = self.cfg.LookupNetwork(self.network_name) self.network_uuid = self.cfg.LookupNetwork(self.network_name)
self.network = self.cfg.GetNetwork(self.network_uuid) if self.network_uuid is None:
if self.network is None:
raise errors.OpPrereqError("Network %s does not exist" % raise errors.OpPrereqError("Network %s does not exist" %
self.network_name, errors.ECODE_INVAL) self.network_name, errors.ECODE_INVAL)
   
self.group_uuid = self.cfg.LookupNodeGroup(self.group_name) self.group_uuid = self.cfg.LookupNodeGroup(self.group_name)
self.group = self.cfg.GetNodeGroup(self.group_uuid) if self.group_uuid is None:
if self.group is None:
raise errors.OpPrereqError("Group %s does not exist" % raise errors.OpPrereqError("Group %s does not exist" %
self.group_name, errors.ECODE_INVAL) self.group_name, errors.ECODE_INVAL)
   
self.share_locks[locking.LEVEL_INSTANCE] = 1
self.needed_locks = { self.needed_locks = {
locking.LEVEL_INSTANCE: [], locking.LEVEL_INSTANCE: [],
locking.LEVEL_NODEGROUP: [self.group_uuid], locking.LEVEL_NODEGROUP: [self.group_uuid],
} }
self.share_locks[locking.LEVEL_INSTANCE] = 1
if self.op.conflicts_check:
self.needed_locks[locking.LEVEL_NETWORK] = [self.network_uuid]
self.share_locks[locking.LEVEL_NETWORK] = 1
   
def DeclareLocks(self, level): def DeclareLocks(self, level):
if level == locking.LEVEL_INSTANCE: if level == locking.LEVEL_INSTANCE:
...@@ -16141,7 +16143,6 @@ class LUNetworkConnect(LogicalUnit): ...@@ -16141,7 +16143,6 @@ class LUNetworkConnect(LogicalUnit):
if self.op.conflicts_check: if self.op.conflicts_check:
self.needed_locks[locking.LEVEL_INSTANCE] = \ self.needed_locks[locking.LEVEL_INSTANCE] = \
self.cfg.GetNodeGroupInstances(self.group_uuid) self.cfg.GetNodeGroupInstances(self.group_uuid)
self.needed_locks[locking.LEVEL_NETWORK] = [self.network_uuid]
   
def BuildHooksEnv(self): def BuildHooksEnv(self):
ret = { ret = {
...@@ -16149,7 +16150,6 @@ class LUNetworkConnect(LogicalUnit): ...@@ -16149,7 +16150,6 @@ class LUNetworkConnect(LogicalUnit):
"GROUP_NETWORK_MODE": self.network_mode, "GROUP_NETWORK_MODE": self.network_mode,
"GROUP_NETWORK_LINK": self.network_link, "GROUP_NETWORK_LINK": self.network_link,
} }
ret.update(_BuildNetworkHookEnvByObject(self.network))
return ret return ret
   
def BuildHooksNodes(self): def BuildHooksNodes(self):
...@@ -16157,14 +16157,10 @@ class LUNetworkConnect(LogicalUnit): ...@@ -16157,14 +16157,10 @@ class LUNetworkConnect(LogicalUnit):
return (nodes, nodes) return (nodes, nodes)
   
def CheckPrereq(self): def CheckPrereq(self):
owned_instances = frozenset(self.owned_locks(locking.LEVEL_INSTANCE))
owned_groups = frozenset(self.owned_locks(locking.LEVEL_NODEGROUP)) owned_groups = frozenset(self.owned_locks(locking.LEVEL_NODEGROUP))
   
assert self.group_uuid in owned_groups assert self.group_uuid in owned_groups
   
# Check if locked instances are still correct
_CheckNodeGroupInstances(self.cfg, self.group_uuid, owned_instances)
l = lambda value: utils.CommaJoin("%s: %s/%s" % (i[0], i[1], i[2]) l = lambda value: utils.CommaJoin("%s: %s/%s" % (i[0], i[1], i[2])
for i in value) for i in value)
   
...@@ -16174,6 +16170,7 @@ class LUNetworkConnect(LogicalUnit): ...@@ -16174,6 +16170,7 @@ class LUNetworkConnect(LogicalUnit):
} }
objects.NIC.CheckParameterSyntax(self.netparams) objects.NIC.CheckParameterSyntax(self.netparams)
   
self.group = self.cfg.GetNodeGroup(self.group_uuid)
#if self.network_mode == constants.NIC_MODE_BRIDGED: #if self.network_mode == constants.NIC_MODE_BRIDGED:
# _CheckNodeGroupBridgesExist(self, self.network_link, self.group_uuid) # _CheckNodeGroupBridgesExist(self, self.network_link, self.group_uuid)
self.connected = False self.connected = False
...@@ -16184,7 +16181,12 @@ class LUNetworkConnect(LogicalUnit): ...@@ -16184,7 +16181,12 @@ class LUNetworkConnect(LogicalUnit):
return return
   
if self.op.conflicts_check: if self.op.conflicts_check:
pool = network.AddressPool(self.network) # Check if locked instances are still correct
owned_instances = frozenset(self.owned_locks(locking.LEVEL_INSTANCE))
_CheckNodeGroupInstances(self.cfg, self.group_uuid, owned_instances)
nobj = self.cfg.GetNetwork(self.network_uuid)
pool = network.AddressPool(nobj)
conflicting_instances = [] conflicting_instances = []
   
for (_, instance) in self.cfg.GetMultiInstanceInfo(owned_instances): for (_, instance) in self.cfg.GetMultiInstanceInfo(owned_instances):
...@@ -16223,18 +16225,17 @@ class LUNetworkDisconnect(LogicalUnit): ...@@ -16223,18 +16225,17 @@ class LUNetworkDisconnect(LogicalUnit):
self.group_name = self.op.group_name self.group_name = self.op.group_name
   
self.network_uuid = self.cfg.LookupNetwork(self.network_name) self.network_uuid = self.cfg.LookupNetwork(self.network_name)
self.network = self.cfg.GetNetwork(self.network_uuid) if self.network_uuid is None:
if self.network is None:
raise errors.OpPrereqError("Network %s does not exist" % raise errors.OpPrereqError("Network %s does not exist" %
self.network_name, errors.ECODE_INVAL) self.network_name, errors.ECODE_INVAL)
   
self.group_uuid = self.cfg.LookupNodeGroup(self.group_name) self.group_uuid = self.cfg.LookupNodeGroup(self.group_name)
self.group = self.cfg.GetNodeGroup(self.group_uuid) if self.group_uuid is None:
if self.group is None:
raise errors.OpPrereqError("Group %s does not exist" % raise errors.OpPrereqError("Group %s does not exist" %
self.group_name, errors.ECODE_INVAL) self.group_name, errors.ECODE_INVAL)
   
self.needed_locks = { self.needed_locks = {
locking.LEVEL_INSTANCE: [],
locking.LEVEL_NODEGROUP: [self.group_uuid], locking.LEVEL_NODEGROUP: [self.group_uuid],
} }
self.share_locks[locking.LEVEL_INSTANCE] = 1 self.share_locks[locking.LEVEL_INSTANCE] = 1
...@@ -16253,7 +16254,6 @@ class LUNetworkDisconnect(LogicalUnit): ...@@ -16253,7 +16254,6 @@ class LUNetworkDisconnect(LogicalUnit):
ret = { ret = {
"GROUP_NAME": self.group_name, "GROUP_NAME": self.group_name,
} }
ret.update(_BuildNetworkHookEnvByObject(self.network))
return ret return ret
   
def BuildHooksNodes(self): def BuildHooksNodes(self):
...@@ -16261,17 +16261,14 @@ class LUNetworkDisconnect(LogicalUnit): ...@@ -16261,17 +16261,14 @@ class LUNetworkDisconnect(LogicalUnit):
return (nodes, nodes) return (nodes, nodes)
   
def CheckPrereq(self): def CheckPrereq(self):
owned_instances = frozenset(self.owned_locks(locking.LEVEL_INSTANCE))
owned_groups = frozenset(self.owned_locks(locking.LEVEL_NODEGROUP)) owned_groups = frozenset(self.owned_locks(locking.LEVEL_NODEGROUP))
   
assert self.group_uuid in owned_groups assert self.group_uuid in owned_groups
   
# Check if locked instances are still correct
_CheckNodeGroupInstances(self.cfg, self.group_uuid, owned_instances)
l = lambda value: utils.CommaJoin("%s: %s/%s" % (i[0], i[1], i[2]) l = lambda value: utils.CommaJoin("%s: %s/%s" % (i[0], i[1], i[2])
for i in value) for i in value)
   
self.group = self.cfg.GetNodeGroup(self.group_uuid)
self.connected = True self.connected = True
if self.network_uuid not in self.group.networks: if self.network_uuid not in self.group.networks:
self.LogWarning("Network '%s' is not mapped to group '%s'", self.LogWarning("Network '%s' is not mapped to group '%s'",
...@@ -16280,6 +16277,10 @@ class LUNetworkDisconnect(LogicalUnit): ...@@ -16280,6 +16277,10 @@ class LUNetworkDisconnect(LogicalUnit):
return return
   
if self.op.conflicts_check: if self.op.conflicts_check:
# Check if locked instances are still correct
owned_instances = frozenset(self.owned_locks(locking.LEVEL_INSTANCE))
_CheckNodeGroupInstances(self.cfg, self.group_uuid, owned_instances)
conflicting_instances = [] conflicting_instances = []
   
for (_, instance) in self.cfg.GetMultiInstanceInfo(owned_instances): for (_, instance) in self.cfg.GetMultiInstanceInfo(owned_instances):
......
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