[PATCHv3] Limit the LV size to VG's free space size
David Lehman
dlehman at redhat.com
Fri Mar 7 15:06:01 UTC 2014
On Fri, 2014-03-07 at 09:57 +0100, Vratislav Podzimek wrote:
> When creating the LV we should check its VG free space size and shrink the LV if
> it exceeds the biggest possible size.
The set looks good now. Thanks.
>
> Related: rhbz#1072999
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
> blivet/devices.py | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/blivet/devices.py b/blivet/devices.py
> index 0903110..84b6e65 100644
> --- a/blivet/devices.py
> +++ b/blivet/devices.py
> @@ -117,6 +117,7 @@ from flags import flags
> from storage_log import log_method_call
> from udev import *
> from formats import get_device_format_class, getFormat, DeviceFormat
> +from size import Size
>
> import gettext
> _ = lambda x: gettext.ldgettext("blivet", x)
> @@ -2714,6 +2715,30 @@ class LVMLogicalVolumeDevice(DMDevice):
> else:
> raise
>
> + def _preCreate(self):
> + super(LVMLogicalVolumeDevice, self)._preCreate()
> +
> + try:
> + vg_info = lvm.vginfo(self.vg.name)
> + except LVMError as lvmerr:
> + msg = "Failed to get free space for the %s VG: %s" % self.vg.name, lvmerr
> + log.error(msg)
> + # nothing more can be done, we don't know the VG's free space
> + return
> +
> + extent_size = Size(spec=vg_info[3] + "MiB")
> + extents_free = int(vg_info[5])
> + can_use = extent_size * extents_free
> +
> + # self.size is in MiB
> + can_use = int(can_use.convertTo("MiB"))
> +
> + if self.size > can_use:
> + msg = "%s LV's size (%s) exceeds the VG's usable free space (%s)," \
> + + "shrinking the LV" % (self.name, self.size, can_use)
> + log.warning(msg)
> + self.size = can_use
> +
> def _create(self):
> """ Create the device. """
> log_method_call(self, self.name, status=self.status)
More information about the anaconda-patches
mailing list