Commit 51cb1581 authored by Luca Bigliardi's avatar Luca Bigliardi
Browse files

Generalize a recursive check on logical disks


Signed-off-by: default avatarLuca Bigliardi <shammash@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 9e33896b
......@@ -2519,22 +2519,6 @@ class LURenameCluster(LogicalUnit):
" the master, please restart manually: %s", msg)
def _RecursiveCheckIfLVMBased(disk):
"""Check if the given disk or its children are lvm-based.
@type disk: L{objects.Disk}
@param disk: the disk to check
@rtype: boolean
@return: boolean indicating whether a LD_LV dev_type was found or not
"""
if disk.children:
for chdisk in disk.children:
if _RecursiveCheckIfLVMBased(chdisk):
return True
return disk.dev_type == constants.LD_LV
class LUSetClusterParams(LogicalUnit):
"""Change the parameters of the cluster.
......@@ -2598,13 +2582,9 @@ class LUSetClusterParams(LogicalUnit):
"""
if self.op.vg_name is not None and not self.op.vg_name:
instances = self.cfg.GetAllInstancesInfo().values()
for inst in instances:
for disk in inst.disks:
if _RecursiveCheckIfLVMBased(disk):
raise errors.OpPrereqError("Cannot disable lvm storage while"
" lvm-based instances exist",
errors.ECODE_INVAL)
if self.cfg.HasAnyDiskOfType(constants.LD_LV):
raise errors.OpPrereqError("Cannot disable lvm storage while lvm-based"
" instances exist", errors.ECODE_INVAL)
node_list = self.acquired_locks[locking.LEVEL_NODE]
......
......@@ -1452,6 +1452,13 @@ class ConfigWriter:
"""
return self._config_data.cluster
@locking.ssynchronized(_config_lock, shared=1)
def HasAnyDiskOfType(self, dev_type):
"""Check if in there is at disk of the given type in the configuration.
"""
return self._config_data.HasAnyDiskOfType(dev_type)
@locking.ssynchronized(_config_lock)
def Update(self, target, feedback_fn):
"""Notify function to be called after updates.
......
......@@ -340,6 +340,21 @@ class ConfigData(ConfigObject):
obj.instances = cls._ContainerFromDicts(obj.instances, dict, Instance)
return obj
def HasAnyDiskOfType(self, dev_type):
"""Check if in there is at disk of the given type in the configuration.
@type dev_type: L{constants.LDS_BLOCK}
@param dev_type: the type to look for
@rtype: boolean
@return: boolean indicating if a disk of the given type was found or not
"""
for instance in self.instances.values():
for disk in instance.disks:
if disk.IsBasedOnDiskType(dev_type):
return True
return False
def UpgradeConfig(self):
"""Fill defaults for missing configuration values.
......@@ -437,6 +452,21 @@ class Disk(ConfigObject):
return 0
return -1
def IsBasedOnDiskType(self, dev_type):
"""Check if the disk or its children are based on the given type.
@type dev_type: L{constants.LDS_BLOCK}
@param dev_type: the type to look for
@rtype: boolean
@return: boolean indicating if a device of the given type was found or not
"""
if self.children:
for child in self.children:
if child.IsBasedOnDiskType(dev_type):
return True
return self.dev_type == dev_type
def GetNodes(self, node):
"""This function returns the nodes this device lives on.
......
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