[PATCH 2/2] Limit the LV size to VG's free space size
David Lehman
dlehman at redhat.com
Wed Mar 5 19:13:45 UTC 2014
On Wed, 2014-03-05 at 18:12 +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.
>
> Related: rhbz#1072999
> Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> ---
> blivet/devices.py | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/blivet/devices.py b/blivet/devices.py
> index 0903110..3aeef28 100644
> --- a/blivet/devices.py
> +++ b/blivet/devices.py
> @@ -2714,6 +2714,22 @@ class LVMLogicalVolumeDevice(DMDevice):
> else:
> raise
>
> + def _preCreate(self):
> + try:
> + vg_info = 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
> +
> + vg_free = Size(spec=vg_info[2])
> + if self.size > vg_free:
> + msg = "%s LV's size (%s) exceeds the %s VG's free space (%s), shrinking the LV" \
> + % (self.name, self.size, self.vg.name, vg_free)
The vg name is already part of self.name here, so feel free to drop the
third %s.
You should see if the free space reported is always a multiple of the
extent size, eg: if there's an lv there that has a size that isn't a
multiple of extent size. It might be safer to look at extent size and
free extents if free space is dodgy like that.
You'll also want to call super(...)._preCreate -- probably first.
> + log.warning(msg)
> + self.size = vg_free
> +
> def _create(self):
> """ Create the device. """
> log_method_call(self, self.name, status=self.status)
More information about the anaconda-patches
mailing list