[rhel6] Shrink the LV if the VG is out of space (#1153376)
Vratislav Podzimek
vpodzime at redhat.com
Tue Dec 9 07:51:16 UTC 2014
On Mon, 2014-12-08 at 12:06 -0500, Samantha N. Bueno wrote:
> On Mon, Dec 08, 2014 at 09:35:35AM +0100, Vratislav Podzimek wrote:
> > On Fri, 2014-12-05 at 12:27 -0800, Brian C. Lane wrote:
> > > lvm doesn't always create the sizes that we expect it to. This can lead
> > > to errors like this:
> > >
> > > Volume group "VolGroup" has insufficient free space (1965 extents): 1968
> > > required.
> > >
> > > This change checks the LV's size against the VG's actual free space and
> > > shrinks the LV to fit if it would be to big.
> > >
> > > This is a port of commit 0c40779fa8f from python-blivet.
> > >
> > > Resolves: rhbz#1153376
> > > ---
> > > storage/devices.py | 33 +++++++++++++++++++++++++++++++++
> > > 1 file changed, 33 insertions(+)
> > >
> > > diff --git a/storage/devices.py b/storage/devices.py
> > > index e179339..8bdf2a5 100644
> > > --- a/storage/devices.py
> > > +++ b/storage/devices.py
> > > @@ -2545,6 +2545,36 @@ class LVMLogicalVolumeDevice(DMDevice):
> > >
> > > return [validpvs[0].path]
> > >
> > > + def _preCreate(self):
> > > + """ Adjust the size of the LV if there isn't enough space in the VG.
> > > +
> > > + size calculations sometimes don't match what lvm actually creates,
> > > + so check the actual free space of the VG and use that if the LV is
> > > + too big.
> > > + """
> > > + try:
> > > + vg_info = lvm.vginfo(self.vg.name)
> > > + except errors.LVMError as lvmerr:
> > > + log.error("Failed to get free space for the %s VG: %s", self.vg.name, lvmerr)
> > > + # nothing more can be done, we don't know the VG's free space
> > > + return
> > > +
> > > + try:
> > > + extent_size = float(vg_info["pe_size"])
> > > + extents_free = int(vg_info["pe_free"])
> > > + except ValueError as e:
> > > + log.error("Failed to get PE information for the %s VG: %s", self.vg.name, e)
> > > + return
> > > +
> > > + log.debug("VG has %s free PEs of size %s", extents_free, extent_size)
> > > +
> > > + can_use = extent_size * extents_free
> > > + 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, intf=None):
> > > """ Create the device. """
> > > log_method_call(self, self.name, status=self.status)
> > > @@ -2561,6 +2591,9 @@ class LVMLogicalVolumeDevice(DMDevice):
> > > self.createParents()
> > > self.setupParents()
> > >
> > > + # Make sure the LV will fit into the real VG size
> > > + self._preCreate()
> > > +
> > > # should we use --zero for safety's sake?
> > > if self.singlePV:
> > > lvm.lvcreate(self.vg.name, self._name, self.size, progress=w,
> > Looks good to me. We just need to remember we have this if we ever add
> > ThinP to RHEL6 anaconda because that required a follow-up patch in
> > python-blivet.
>
> https://bugzilla.redhat.com/show_bug.cgi?id=1083459 has been approved.
Wow, that will be fun. Thanks for the heads up.
--
Vratislav Podzimek
Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
More information about the anaconda-patches
mailing list