[PATCH 2/2] Limit the LV size to VG's free space size

Vratislav Podzimek vpodzime at redhat.com
Thu Mar 6 09:43:25 UTC 2014


On Wed, 2014-03-05 at 13:13 -0600, David Lehman wrote:
> 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.
Good point, thanks!

> 
> 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.
I've added a check for that, but isn't it better to always use
free_extents * extent_size as the limit then? That's what actually
limits the LV size in all cases, right?

> 
> You'll also want to call super(...)._preCreate -- probably first.
True, done.

Sending a v2 of the patch. If we decide to always use free_extents *
extent_size I'll do that change locally before pushing.

-- 
Vratislav Podzimek

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



More information about the anaconda-patches mailing list