[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[PATCH] Fix size calculation for MD arrays.



---
 storage/devices.py |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/storage/devices.py b/storage/devices.py
index d0b00b8..79a4bd5 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -2060,11 +2060,32 @@ class MDRaidArrayDevice(StorageDevice):
                                                 % (self.path, self.uuid))
 
     @property
+    def smallestMember(self):
+        try:
+            smallest = sorted(self.devices, key=lambda d: d.size)[0]
+        except IndexError:
+            smallest = None
+        return smallest
+
+    @property
     def size(self):
-        size = None
-        for device in self.devices:
-            if size is None or device.size < size:
-                size = device.size
+        if not self.devices:
+            return 0
+
+        size = 0
+        if not self.exists or not self.partedDevice:
+            if self.level == 0:
+                size = self.memberDevices * self.smallestMember.size
+            elif self.level == 1:
+                size = self.smallestMember.size
+            elif self.level == 5:
+                size = (self.memberDevices - 1) * self.smallestMember.size
+            elif self.level == 6:
+                size = (self.memberDevices - 2) * self.smallestMember.size
+            elif self.level == 10:
+               size = (self.memberDevices / 2.0) * self.smallestMember.size
+        else:
+            size = super(MDRaidArrayDevice, self).size
 
         return size
 
-- 
1.6.0.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]