diff --git a/lib/cmdlib.py b/lib/cmdlib.py index e989b2316f7927252bae43d732815c65d03c3e46..e08d903dc3a419e26e1bb6c15b8ec5284508a7f9 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -4907,9 +4907,8 @@ def _CheckNodesFreeDiskPerVG(lu, nodenames, req_sizes): or we cannot check the node """ - if req_sizes is not None: - for vg, req_size in req_sizes.iteritems(): - _CheckNodesFreeDiskOnVG(lu, nodenames, vg, req_size) + for vg, req_size in req_sizes.items(): + _CheckNodesFreeDiskOnVG(lu, nodenames, vg, req_size) def _CheckNodesFreeDiskOnVG(lu, nodenames, vg, requested): @@ -6686,11 +6685,11 @@ def _ComputeDiskSizePerVG(disk_template, disks): # Required free disk space as a function of disk and swap space req_size_dict = { - constants.DT_DISKLESS: None, + constants.DT_DISKLESS: {}, constants.DT_PLAIN: _compute(disks, 0), # 128 MB are added for drbd metadata for each disk constants.DT_DRBD8: _compute(disks, 128), - constants.DT_FILE: None, + constants.DT_FILE: {}, } if disk_template not in req_size_dict: @@ -8646,7 +8645,7 @@ class LUGrowDisk(LogicalUnit): # TODO: check the free disk space for file, when that feature # will be supported _CheckNodesFreeDiskPerVG(self, nodenames, - {self.disk.physical_id[0]: self.op.amount}) + self.disk.ComputeGrowth(self.op.amount)) def Exec(self, feedback_fn): """Execute disk grow. diff --git a/lib/objects.py b/lib/objects.py index 274c75641faab685c23b672708f591b4513833f3..ce1521c5ec212dd85315bc4287cfb5b6139ed06b 100644 --- a/lib/objects.py +++ b/lib/objects.py @@ -1,7 +1,7 @@ # # -# Copyright (C) 2006, 2007, 2008, 2009, 2010 Google Inc. +# Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Google Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -528,6 +528,28 @@ class Disk(ConfigObject): # be different) return result + def ComputeGrowth(self, amount): + """Compute the per-VG growth requirements. + + This only works for VG-based disks. + + @type amount: integer + @param amount: the desired increase in (user-visible) disk space + @rtype: dict + @return: a dictionary of volume-groups and the required size + + """ + if self.dev_type == constants.LD_LV: + return {self.logical_id[0]: amount} + elif self.dev_type == constants.LD_DRBD8: + if self.children: + return self.children[0].ComputeGrowth(amount) + else: + return {} + else: + # Other disk types do not require VG space + return {} + def RecordGrow(self, amount): """Update the size of this disk after growth.