diff --git a/lib/cmdlib.py b/lib/cmdlib.py index b34cef9b84baa9e12a5a6305aede0f2fe7c4371a..b554321fb6539855c2625d8fb8dd38f31dc56539 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -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] diff --git a/lib/config.py b/lib/config.py index c81f201d5e075d134d61084708a11a6c7143ba8d..371a3994b3083e25401bc783c1c980b95bba56a1 100644 --- a/lib/config.py +++ b/lib/config.py @@ -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. diff --git a/lib/objects.py b/lib/objects.py index adb2756b166297c0034de0734ee42344bfd6876d..9e9163cbbade3db9907f7623ca5f201cb63ae240 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -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.