[blivet:master 8/9] Revise mdadd.

mulhern amulhern at redhat.com
Mon Aug 4 15:56:55 UTC 2014


1) LinearRAID mdadm call will fail if raid_devices is passed.
2) RAID0 mdadm call will fail if the the raid_devices number is not exactly
right, so use mddetail to find the current value and increment that by one.

Change calls accordingly.
---
 blivet/devicelibs/mdraid.py | 28 ++++++++++++++++++----------
 blivet/devices.py           | 19 ++++++++++++++-----
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
index d10bae0..cb36f32 100644
--- a/blivet/devicelibs/mdraid.py
+++ b/blivet/devicelibs/mdraid.py
@@ -156,31 +156,39 @@ def mdnominate(device):
     except MDRaidError as msg:
         raise MDRaidError("mdnominate failed for %s: %s" % (device, msg))
 
-def mdadd(array, device, raid_devices=None):
+def mdadd(array, device, grow_mode=False, raid_devices=None):
     """ Add a device to an array.
 
         :param str array: path to the array to add the device to
         :param str device: path to the device to add to the array
-        :keyword int raid_devices: the number of active member devices
+        :keyword bool grow_mode: use grow mode
+        :keyword int raid_devices: the intended number of active member devices
         :rtype: NoneType
         :raises: MDRaidError
 
-        The raid_devices parameter is used when adding devices to a raid
+        The grow_devices parameter is used when adding devices to a raid
         array that has no actual redundancy. In this case it is necessary
         to explicitly grow the array all at once rather than manage it in
         the sense of adding spares.
 
-        Whether the new device will be added as a spare or an active member is
-        decided by mdadm.
+        If raid_devices is set, and grow_mode is True, then the intended
+        number of devices after this device is added is specified
+        using the --raid-devices flag. If grow is not True then raid_devices
+        is ignored. For linear arrays, specifying raid_devices will result
+        in a failure.
+
+        Whether the new device will be added as a spare or an active member
+        when not in grow mode is decided by mdadm.
 
         .. seealso:: mdnominate
     """
-    if raid_devices is None:
-        args = [array, "--add"]
+    if grow_mode:
+        args = ["--grow", array]
+        if raid_devices:
+            args.extend(["--raid-devices", str(raid_devices)])
     else:
-        args = ["--grow", array, "--raid-devices", str(raid_devices), "--add"]
-
-    args.append(device)
+        args = [array]
+    args.extend(["--add", device])
 
     try:
         mdadm(args)
diff --git a/blivet/devices.py b/blivet/devices.py
index c4259f5..5a6e11e 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -4056,13 +4056,22 @@ class MDRaidArrayDevice(ContainerDevice):
         mdraid.mdremove(self.path, member.path, fail=fail)
 
     def _add(self, member):
+        """ Add a member device to an array.
+
+           :param str member: the member's path
+
+           :raises: MDRaidError
+        """
         self.setup()
-        if self.level is raid.Container or self.level.has_redundancy():
-            raid_devices = None
-        else:
-            raid_devices = self.memberDevices
 
-        mdraid.mdadd(self.path, member.path, raid_devices=raid_devices)
+        grow_mode = False
+        raid_devices = None
+        if not self.level is raid.Container and not self.level.has_redundancy():
+            grow_mode = True
+            if self.level is not raid.Linear:
+                raid_devices = int(mdraid.mddetail(self.name)['RAID DEVICES']) + 1
+
+        mdraid.mdadd(self.path, member.path, grow_mode=grow_mode, raid_devices=raid_devices)
 
     @property
     def formatArgs(self):
-- 
1.9.3



More information about the anaconda-patches mailing list