Commit 6d33a6eb authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix growing of DRBD disks

Patch 03941a26

 made disk growth VG-aware, but the code has a bug: it
only works for LD_LV disks, and not LD_DRBD. To fix it, we add a
generic function to compute the per-VG growth requirements, and switch
to using that instead of manual build.

Furthermore, since the function _CheckNodesFreeDiskPerVG always takes
its input from this new function or _ComputeDiskSizePerVG, we change
the latter to always return a dict (possibly empty), instead of either
a dict or None. This makes the types more consistent.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent b288b6f3
......@@ -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.
......
#
#
# 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.
......
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