[blivet:rhel7/master 3/3] Calculate some derived quantities from raw device (#1076055)

mulhern amulhern at redhat.com
Thu Sep 25 18:03:02 UTC 2014


Related: rhbz#1076055

For LUKSDevice, calculate more than size from raw device.

Use the device format's minSize to find the difference between the raw
device's size quantity and the LUKS devices size quantity instead of using
crypto.LUKS_METADATA_SIZE.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devices.py | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/blivet/devices.py b/blivet/devices.py
index 9da51d8..3757b79 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -34,7 +34,6 @@ from .devicelibs import lvm
 from .devicelibs import dm
 from .devicelibs import loop
 from .devicelibs import btrfs
-from .devicelibs import crypto
 from .devicelibs import raid
 import parted
 import _ped
@@ -2344,13 +2343,42 @@ class LUKSDevice(DMCryptDevice):
         return self.slave
 
     @property
+    def maxSize(self):
+        max_size = self.slave.maxSize
+        if not max_size:
+            return max_size
+
+        max_size = max_size - self.format.minSize
+        if max_size < 0:
+            return 0
+
+        return max_size
+
+    @property
+    def minSize(self):
+        return self.slave.minSize + self.format.minSize
+
+    @property
     def size(self):
         if not self.exists or not self.partedDevice:
-            size = self.slave.size - crypto.LUKS_METADATA_SIZE
+            size = self.slave.size - self.format.minSize
         else:
             size = Size(self.partedDevice.getLength(unit="B"))
         return size
 
+    def _setSize(self, size):
+        self.slave.size = size + self.format.minSize
+
+    def _setTargetSize(self, newsize):
+        self.slave._setTargetSize(newsize + self.format.minSize)
+
+    def _getTargetSize(self):
+        return self.slave._getTargetSize() - self.format.minSize
+
+    @property
+    def currentSize(self):
+        return self.slave.currentSize + self.format.minSize
+
     def _postCreate(self):
         self.name = self.slave.format.mapName
         StorageDevice._postCreate(self)
-- 
1.9.3



More information about the anaconda-patches mailing list