]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
Don't let incremental add devices to active arrays.
authorNeilBrown <neilb@suse.de>
Tue, 6 Jul 2010 02:04:40 +0000 (12:04 +1000)
committerNeilBrown <neilb@suse.de>
Tue, 6 Jul 2010 02:04:40 +0000 (12:04 +1000)
Adding devices to active arrays in --incremental is a bit dubious.

Normally the array won't be activated until all expected devices are
present, so this situation would mean that the given device is not
expected, so is probably failed.  In that case it should only be added
by explicit sysadmin request.

However if --run was given, then quite possibly the array was
assembled earlier when not complete, so it is less clear whether it is
wrong to add this device or not.  In that case add it as that is
generally safest.

It would be nice to allow policy for this to be explicitly given by
sysadmin.

Signed-off-by: NeilBrown <neilb@suse.de>
Incremental.c

index a99811d8a78c396c457bb27bed00df727abdce4f..7f67535bee724075361e2a9bb5c5a5e1d35f909b 100644 (file)
@@ -368,6 +368,22 @@ int Incremental(char *devname, int verbose, int runstop,
                else
                        strcpy(chosen_name, devnum2devname(mp->devnum));
 
+               /* It is generally not OK to add drives to a running array
+                * as they are probably missing because they failed.
+                * However if runstop is 1, then the array was possibly
+                * started early and our best be is to add this anyway.
+                * It would probably be good to allow explicit policy
+                * statement about this.
+                */
+               if (runstop < 1) {
+                       if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) {
+                               fprintf(stderr, Name
+                                       ": not adding %s to active array (without --run) %s\n",
+                                       devname, chosen_name);
+                               close(mdfd);
+                               return 2;
+                       }
+               }
                sra = sysfs_read(mdfd, fd2devnum(mdfd), (GET_DEVS | GET_STATE));
 
                if (sra->devs) {