]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Manage: Add support for --re-add faulty
authorNeilBrown <neilb@suse.de>
Tue, 27 Nov 2012 23:19:52 +0000 (10:19 +1100)
committerNeilBrown <neilb@suse.de>
Tue, 27 Nov 2012 23:19:52 +0000 (10:19 +1100)
mdadm /dev/mdXX --re-add faulty

will identify any faulty devices in the array, remove them, and
--re-add them.

Signed-off-by: NeilBrown <neilb@suse.de>
Manage.c
mdadm.8.in

index 3d713a32a3520eb6e3259482b49836bc956e0576..4d9c0d2f6ed9e21495ec70b74093e524a3d2bc73 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -1084,6 +1084,8 @@ int Manage_subdevs(char *devname, int fd,
         *        it must be unpaired, and is an error.
         *  'M' - this is created by a 'missing' target.  It is a slight
         *        variant on 'A'
+        *  'F' - Another variant of 'A', where the device was faulty
+        *        so must be removed from the array first.
         *
         * For 'f' and 'r', the device can also be a kernel-internal
         * name such as 'sdb'.
@@ -1128,13 +1130,15 @@ int Manage_subdevs(char *devname, int fd,
 
                if (strcmp(dv->devname, "failed") == 0 ||
                    strcmp(dv->devname, "faulty") == 0) {
-                       if (dv->disposition != 'r') {
+                       if (dv->disposition != 'A'
+                           && dv->disposition != 'r') {
                                pr_err("%s only meaningful "
-                                       "with -r, not -%c\n",
+                                       "with -r or --re-add, not -%c\n",
                                        dv->devname, dv->disposition);
                                goto abort;
                        }
-                       add_faulty(dv, fd, 'r');
+                       add_faulty(dv, fd, (dv->disposition == 'A'
+                                           ? 'F' : 'r'));
                        continue;
                }
                if (strcmp(dv->devname, "detached") == 0) {
@@ -1245,7 +1249,8 @@ int Manage_subdevs(char *devname, int fd,
                        goto abort;
                case 'a':
                case 'A':
-               case 'M':
+               case 'M': /* --re-add missing */
+               case 'F': /* --re-add faulty  */
                        /* add the device */
                        if (subarray) {
                                pr_err("Cannot add disks to a"
@@ -1253,6 +1258,10 @@ int Manage_subdevs(char *devname, int fd,
                                        " operation on the parent container\n");
                                goto abort;
                        }
+                       if (dv->disposition == 'F')
+                               /* Need to remove first */
+                               ioctl(fd, HOT_REMOVE_DISK,
+                                     (unsigned long)stb.st_rdev);
                        /* Make sure it isn't in use (in 2.6 or later) */
                        tfd = dev_open(dv->devname, O_RDONLY|O_EXCL);
                        if (tfd >= 0) {
index 23e31228d37b9074f9410ceaabecbe97f2f824cc..535cc392001151bc364aa8adc8722b7fb198b830 100644 (file)
@@ -1260,9 +1260,21 @@ explanation of their use.
 
 If the device name given is
 .B missing
-then mdadm will try to find any device that looks like it should be
+then
+.I mdadm
+will try to find any device that looks like it should be
 part of the array but isn't and will try to re\-add all such devices.
 
+If the device name given is
+.B faulty
+then
+.I mdadm
+will find all devices in the array that are marked
+.BR faulty ,
+remove them and attempt to immediately re\-add them.  This can be
+useful if you are certain that the reason for failure has been
+resolved.
+
 .TP
 .BR \-r ", " \-\-remove
 remove listed devices.  They must not be active.  i.e. they should