[master 2/4] Put the LVM metadata size calculation into a separate property

vpodzime installerbot-noreply at redhat.com
Wed Nov 4 19:49:42 UTC 2015


From: Vratislav Podzimek <vpodzime at redhat.com>

By default LVM puts metadata on every PV a VG consists of. We need to account
for that space when calculating the size of the VG, but it's useful in other
cases too. Thus the value should be available as a separate property.
---
 blivet/devices/lvm.py | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/blivet/devices/lvm.py b/blivet/devices/lvm.py
index 39d245c..bc4cef3 100644
--- a/blivet/devices/lvm.py
+++ b/blivet/devices/lvm.py
@@ -351,12 +351,8 @@ def reservedSpace(self):
         return self.align(reserved, roundup=True)
 
     @property
-    def size(self):
-        """ The size of this VG """
-        # TODO: just ask lvm if isModified returns False
-
-        # sum up the sizes of the PVs, subtract the unusable (meta data) space
-        # and align to pesize
+    def lvm_metadata_size(self):
+        """The amount of the space reserved for LVM metadata in this VG's PVs"""
         # NOTE: we either specify data alignment in a PV or the default is used
         #       which is both handled by pv.format.peStart, but LVM takes into
         #       account also the underlying block device which means that e.g.
@@ -366,14 +362,25 @@ def size(self):
         # TODO: move this to either LVMPhysicalVolume's peStart property once
         #       formats know about their devices or to a new LVMPhysicalVolumeDevice
         #       class once it exists
-        avail = Size(0)
+        diff = Size(0)
         for pv in self.pvs:
             if isinstance(pv, MDRaidArrayDevice):
-                avail += self.align(pv.size - 2 * pv.format.peStart)
+                diff += self.align(pv.size) - self.align(pv.size - 2 * pv.format.peStart)
             else:
-                avail += self.align(pv.size - pv.format.peStart)
+                diff += self.align(pv.size) - self.align(pv.size - pv.format.peStart)
+
+        return diff
+
+    @property
+    def size(self):
+        """ The size of this VG """
+        # TODO: just ask lvm if isModified returns False
 
-        return avail
+        # sum up the sizes of the PVs, subtract the unusable (meta data) space
+        size = sum(pv.size for pv in self.pvs)
+        size -= self.lvm_metadata_size
+
+        return size
 
     @property
     def extents(self):


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/ca1ea1589913072a0c3a308ee9c316ee34c7d100


More information about the anaconda-patches mailing list