[blivet:f21-branch 07/14] Split mdadd into separate functions.

mulhern amulhern at redhat.com
Mon Sep 29 17:22:54 UTC 2014


Incremental mode is really considerably different from add mode.

For one thing, it may cause the array to be started if it was not already,
based on the number of devices in the array and the number that ought
to be in the array.

Signed-off-by: mulhern <amulhern at redhat.com>
---
 blivet/devicelibs/mdraid.py          | 36 ++++++++++++++++++++++++++----------
 blivet/devices.py                    |  2 +-
 tests/devicelibs_test/mdraid_test.py | 10 +++++-----
 3 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/blivet/devicelibs/mdraid.py b/blivet/devicelibs/mdraid.py
index c4c4264..a391c3f 100644
--- a/blivet/devicelibs/mdraid.py
+++ b/blivet/devicelibs/mdraid.py
@@ -135,13 +135,35 @@ def mddestroy(device):
     except MDRaidError as msg:
         raise MDRaidError("mddestroy failed for %s: %s" % (device, msg))
 
-def mdadd(array, device, incremental=False, raid_devices=None):
+def mdnominate(device):
+    """ Attempt to add a device to the array to which it belongs.
+
+        Belonging is determined by mdadm's rules.
+
+        May start the array once a sufficient number of devices are added
+        to the array.
+
+        :param str device: path to the device to add
+        :rtype: NoneType
+        :raises: MDRaidError
+
+        .. seealso:: mdadd
+    """
+    args = ['--incremental', '--quiet', device]
+
+    try:
+        mdadm(args)
+    except MDRaidError as msg:
+        raise MDRaidError("mdadd failed for %s: %s" % (device, msg))
+
+def mdadd(array, device, 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 bool incremental: add the device incrementally (see note below)
         :keyword int raid_devices: the number of active member devices
+        :rtype: NoneType
+        :raises: MDRaidError
 
         The raid_devices parameter is used when adding devices to a raid
         array that has no actual redundancy. In this case it is necessary
@@ -151,15 +173,9 @@ def mdadd(array, device, incremental=False, raid_devices=None):
         Whether the new device will be added as a spare or an active member is
         decided by mdadm.
 
-        .. note::
-
-            Incremental add is used during block device discovery and is a
-            different operation than changing the member set of an array.
-
+        .. seealso:: mdnominate
     """
-    if incremental:
-        args = ["--incremental", "--quiet"]
-    elif raid_devices is None:
+    if raid_devices is None:
         args = [array, "--add"]
     else:
         args = ["--grow", array, "--raid-devices", str(raid_devices), "--add"]
diff --git a/blivet/devices.py b/blivet/devices.py
index 2a53ad9..476c384 100644
--- a/blivet/devices.py
+++ b/blivet/devices.py
@@ -3907,7 +3907,7 @@ class MDRaidArrayDevice(ContainerDevice):
 
             if self.spares <= 0:
                 try:
-                    mdraid.mdadd(None, member.path, incremental=True)
+                    mdraid.mdnominate(member.path)
                     # mdadd causes udev events
                     udev.settle()
                 except errors.MDRaidError as e:
diff --git a/tests/devicelibs_test/mdraid_test.py b/tests/devicelibs_test/mdraid_test.py
index 2ed7a2a..042f1eb 100755
--- a/tests/devicelibs_test/mdraid_test.py
+++ b/tests/devicelibs_test/mdraid_test.py
@@ -144,9 +144,9 @@ class SimpleRaidTest(MDRaidAsRootTestCase):
         self.assertIsNone(mdraid.mdremove(self._dev_name, self.loopDevices[2], fail=True))
         time.sleep(2) # wait for raid to settle
 
-        # can not re-add incrementally, because the array is active
+        # can not re-add in incremental mode because the array is active
         with self.assertRaises(MDRaidError):
-            mdraid.mdadd(None, self.loopDevices[2], incremental=True)
+            mdraid.mdnominate(self.loopDevices[2])
 
         ##
         ## mddeactivate
@@ -154,12 +154,12 @@ class SimpleRaidTest(MDRaidAsRootTestCase):
         # pass
         self.assertIsNone(mdraid.mddeactivate(self._dev_name))
 
-        # once the array is deactivated, can add incrementally
-        self.assertIsNone(mdraid.mdadd(None, self.loopDevices[2], incremental=True))
+        # once the array is deactivated, can add in incremental mode
+        self.assertIsNone(mdraid.mdnominate(self.loopDevices[2]))
 
         # but cannot re-add twice
         with self.assertRaises(MDRaidError):
-            mdraid.mdadd(None, self.loopDevices[2], incremental=True)
+            mdraid.mdnominate(self.loopDevices[2])
 
         # fail
         with self.assertRaises(MDRaidError):
-- 
1.9.3



More information about the anaconda-patches mailing list