When creating an LVM setup on top of RAID, we add some extra extents to make sure the metadata will fit in. However, when reporting free space in a VG or when creating an LV in a VG the size of which was pushed to the limit, we need to take those extra metadata into account as well.
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com --- blivet/devicefactory.py | 9 ++++++++- blivet/devices.py | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/blivet/devicefactory.py b/blivet/devicefactory.py index 2d04005..5e0b7f1 100644 --- a/blivet/devicefactory.py +++ b/blivet/devicefactory.py @@ -1138,7 +1138,7 @@ class LVMFactory(DeviceFactory): if self.container and self.container.exists: return size
- if self.container_size == 0: + if self.container_size == SIZE_POLICY_AUTO: # automatic container size management if self.container: size += sum([p.size for p in self.container.parents]) @@ -1213,6 +1213,13 @@ class LVMFactory(DeviceFactory):
def _get_new_device(self, *args, **kwargs): """ Create and return the factory device as a StorageDevice. """ + + if self.container_raid_level and self.container_size in [SIZE_POLICY_AUTO, + SIZE_POLICY_MAX]: + # container pushed to the limit, but we need some extra space for + # metadata, so we need to make the LV smaller + extra_md_space = LVM_PE_SIZE * len(self.disks) * 5 + kwargs["size"] -= extra_md_space return self.storage.newLV(*args, **kwargs)
def _set_name(self): diff --git a/blivet/devices.py b/blivet/devices.py index a607c1b..215b464 100644 --- a/blivet/devices.py +++ b/blivet/devices.py @@ -2424,9 +2424,19 @@ class LVMVolumeGroupDevice(DMDevice): """ The amount of free space in this VG (in MB). """ # TODO: just ask lvm if isModified returns False
+ # get the number of disks used by PVs on RAID (if any) + raid_disks = 0 + for pv in self.pvs: + if isinstance(pv, MDRaidArrayDevice): + raid_disks = max([raid_disks, len(pv.disks)]) + # total the sizes of any LVs log.debug("%s size is %dMB" % (self.name, self.size)) used = sum(lv.vgSpaceUsed for lv in self.lvs) + self.snapshotSpace + if raid_disks: + # LV on RAID allocates (5 * num_disks) extra extents for metadata + # (see the devicefactory.LVMFactory._get_total_space method) + used += len(self.lvs) * 5 * raid_disks * self.peSize used += self.reservedSpace used += self.poolMetaData free = self.size - used