From 6ebfef424ad3aa3441773856de088daf77dcaa7b Mon Sep 17 00:00:00 2001 From: Bernardo Dal Seno <bdalseno@google.com> Date: Thu, 29 Nov 2012 19:35:31 +0100 Subject: [PATCH] LUs raise an error if they cannot handle exclusive_storage This happens when the exclusive_storage flag is set, and the requested operation is incompatible with the flag or not yet supported. Signed-off-by: Bernardo Dal Seno <bdalseno@google.com> Reviewed-by: Iustin Pop <iustin@google.com> --- lib/cmdlib.py | 43 +++++++++++++++++++++++++++++++++++++------ lib/constants.py | 11 +++++++++++ 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 478e7675e..74abf2106 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -10495,6 +10495,16 @@ class LUInstanceCreate(LogicalUnit): " from the first disk's node group will be" " used") + if not self.op.disk_template in constants.DTS_EXCL_STORAGE: + nodes = [pnode] + if self.op.disk_template in constants.DTS_INT_MIRROR: + nodes.append(snode) + has_es = lambda n: _IsExclusiveStorageEnabledNode(self.cfg, n) + if compat.any(map(has_es, nodes)): + raise errors.OpPrereqError("Disk template %s not supported with" + " exclusive storage" % self.op.disk_template, + errors.ECODE_STATE) + nodenames = [pnode.name] + self.secondaries # Verify instance specs @@ -12416,14 +12426,22 @@ class LUInstanceGrowDisk(LogicalUnit): utils.FormatUnit(self.delta, "h"), errors.ECODE_INVAL) - if instance.disk_template not in (constants.DT_FILE, - constants.DT_SHARED_FILE, - constants.DT_RBD, - constants.DT_EXT): + self._CheckDiskSpace(nodenames, self.disk.ComputeGrowth(self.delta)) + + def _CheckDiskSpace(self, nodenames, req_vgspace): + template = self.instance.disk_template + if template not in (constants.DTS_NO_FREE_SPACE_CHECK): # TODO: check the free disk space for file, when that feature will be # supported - _CheckNodesFreeDiskPerVG(self, nodenames, - self.disk.ComputeGrowth(self.delta)) + nodes = map(self.cfg.GetNodeInfo, nodenames) + es_nodes = filter(lambda n: _IsExclusiveStorageEnabledNode(self.cfg, n), + nodes) + if es_nodes: + # With exclusive storage we need to something smarter than just looking + # at free space; for now, let's simply abort the operation. + raise errors.OpPrereqError("Cannot grow disks when exclusive_storage" + " is enabled", errors.ECODE_STATE) + _CheckNodesFreeDiskPerVG(self, nodenames, req_vgspace) def Exec(self, feedback_fn): """Execute disk grow. @@ -13292,6 +13310,19 @@ class LUInstanceSetParams(LogicalUnit): " from the first disk's node group will be" " used") + if not self.op.disk_template in constants.DTS_EXCL_STORAGE: + # Make sure none of the nodes require exclusive storage + nodes = [pnode_info] + if self.op.disk_template in constants.DTS_INT_MIRROR: + assert snode_info + nodes.append(snode_info) + has_es = lambda n: _IsExclusiveStorageEnabledNode(self.cfg, n) + if compat.any(map(has_es, nodes)): + errmsg = ("Cannot convert disk template from %s to %s when exclusive" + " storage is enabled" % (instance.disk_template, + self.op.disk_template)) + raise errors.OpPrereqError(errmsg, errors.ECODE_STATE) + def CheckPrereq(self): """Check prerequisites. diff --git a/lib/constants.py b/lib/constants.py index 2501f0be5..5bc6cf36c 100644 --- a/lib/constants.py +++ b/lib/constants.py @@ -420,6 +420,17 @@ DTS_FILEBASED = compat.UniqueFrozenset([ DT_SHARED_FILE, ]) +# the set of disk templates that are supported by exclusive_storage +DTS_EXCL_STORAGE = frozenset([DT_PLAIN]) + +# templates for which we don't perform checks on free space +DTS_NO_FREE_SPACE_CHECK = frozenset([ + DT_FILE, + DT_SHARED_FILE, + DT_RBD, + DT_EXT, + ]) + # logical disk types LD_LV = "lvm" LD_DRBD8 = "drbd8" -- GitLab