[PATCHv2] Limit the LV size to VG's free space size

Vratislav Podzimek vpodzime at redhat.com
Fri Mar 7 08:45:51 UTC 2014


On Thu, 2014-03-06 at 08:57 -0600, David Lehman wrote:
> On Thu, 2014-03-06 at 10:45 +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 | 25 +++++++++++++++++++++++++
> >  1 file changed, 25 insertions(+)
> > 
> > diff --git a/blivet/devices.py b/blivet/devices.py
> > index 0903110..d833373 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
> > +
> > +        vg_free = Size(spec=vg_info[2] + "MB")
> > +        extent_size = Size(spec=vg_info[3] + "MB")
> 
> I think it would be safer to just use (extents * extent_size). Also, I'm
> fairly certain they are reported in MiB -- not MB.
Good catch!

> 
> > +        extents_free = int(vg_info[5])
> > +        if vg_free % extent_size != 0:
> > +            # reported free space not a multiple of extents, use multiple of extents
> > +            vg_free = extent_size * extents_free
> > +
> > +        if self.size > vg_free:
> > +            msg = "%s LV's size (%s) exceeds the VG's free space (%s), shrinking the LV" \
> > +                  % (self.name, self.size, vg_free)
> > +            log.warning(msg)
> > +            self.size = vg_free

> Be careful with the types here on rhel7-branch -- size should be in MiB.
True.

Sending v3 of the patch. Please tell me if it looks good together with
the other one.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list