]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Add support for --add-spare
authorNeilBrown <neilb@suse.de>
Wed, 30 Oct 2013 23:41:50 +0000 (10:41 +1100)
committerNeilBrown <neilb@suse.de>
Wed, 30 Oct 2013 23:41:50 +0000 (10:41 +1100)
--add-spare is like --add, but a --re-add is never attempted.
So it is equivalent to two separate commands:

 --zero-metadata
 --add

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

index c8276ca1f72d40baa76535b8f0dace52ba86ab12..059cf5b8cc83cac15ae52b25d1312f9d0dcc956f 100644 (file)
--- a/Manage.c
+++ b/Manage.c
@@ -783,7 +783,8 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
                                break;
                        }
                /* FIXME this is a bad test to be using */
-               if (!tst->sb && dv->disposition != 'a') {
+               if (!tst->sb && (dv->disposition != 'a'
+                                && dv->disposition != 'S')) {
                        /* we are re-adding a device to a
                         * completely dead array - have to depend
                         * on kernel to check
@@ -813,7 +814,7 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
                        dev_st = dup_super(tst);
                        dev_st->ss->load_super(dev_st, tfd, NULL);
                }
-               if (dev_st && dev_st->sb) {
+               if (dev_st && dev_st->sb && dv->disposition != 'S') {
                        int rv = attempt_re_add(fd, tfd, dv,
                                                dev_st, tst,
                                                rdev,
@@ -1237,6 +1238,7 @@ int Manage_subdevs(char *devname, int fd,
         *  'a' - add the device
         *         try HOT_ADD_DISK
         *         If that fails EINVAL, try ADD_NEW_DISK
+        *  'S' - add the device as a spare - don't try re-add
         *  'A' - re-add the device
         *  'r' - remove the device: HOT_REMOVE_DISK
         *        device can be 'faulty' or 'detached' in which case all
@@ -1447,6 +1449,7 @@ int Manage_subdevs(char *devname, int fd,
                                dv->devname, dv->disposition);
                        goto abort;
                case 'a':
+               case 'S': /* --add-spare */
                case 'A':
                case 'M': /* --re-add missing */
                case 'F': /* --re-add faulty  */
index d742cc70d16d271269ca8221c6bd4e21a61c8549..45046ef71578afa70982b26b78a6a3bddff040ad 100644 (file)
--- a/ReadMe.c
+++ b/ReadMe.c
@@ -153,6 +153,7 @@ struct option long_options[] = {
 
     /* Management */
     {"add",       0, 0, Add},
+    {"add-spare", 0, 0, AddSpare},
     {"remove",    0, 0, Remove},
     {"fail",      0, 0, Fail},
     {"set-faulty",0, 0, Fail},
index 006ae59f42ecfdabf75744274f902fcdb950b7d7..61cb4f7100dc9c7616bcc245b3d0f0247061d0fb 100644 (file)
@@ -214,7 +214,10 @@ to detect and assemble arrays \(em possibly in an
 
 .P
 If a device is given before any options, or if the first option is
+and of
 .BR \-\-add ,
+.BR \-\-re\-add ,
+.BR \-\-add\-spare ,
 .BR \-\-fail ,
 .BR \-\-remove ,
 or
@@ -1297,6 +1300,15 @@ 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
+.B \-\-add\-spare
+Add a device as a spare.  This is similar to
+.B \-\-add
+except that it does not attempt
+.B \-\-re\-add
+first.  The device will be added as a spare even if it looks like it
+could be an recent member of the array.
+
 .TP
 .BR \-r ", " \-\-remove
 remove listed devices.  They must not be active.  i.e. they should
diff --git a/mdadm.c b/mdadm.c
index d3cf0fad87bf94f1910854e397c47bcfba0799ae..359e9f914aa22e762cf035913ce6738c7d498671 100644 (file)
--- a/mdadm.c
+++ b/mdadm.c
@@ -187,6 +187,7 @@ int main(int argc, char *argv[])
                        break;
                case 'a':
                case Add:
+               case AddSpare:
                case 'r':
                case Remove:
                case Replace:
@@ -915,6 +916,9 @@ int main(int argc, char *argv[])
                case O(MANAGE,Add): /* add a drive */
                        devmode = 'a';
                        continue;
+               case O(MANAGE,AddSpare): /* add drive - never re-add */
+                       devmode = 'S';
+                       continue;
                case O(MANAGE,ReAdd):
                        devmode = 'A';
                        continue;
diff --git a/mdadm.h b/mdadm.h
index cb207c9b2b00805ce9d599707beaec5becceec6e..7cfdd8fd1cf9b97bacc263c355bb2eef03779052 100644 (file)
--- a/mdadm.h
+++ b/mdadm.h
@@ -311,6 +311,7 @@ enum special_options {
        Brief,
        ManageOpt,
        Add,
+       AddSpare,
        Remove,
        Fail,
        Replace,