summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2010-07-06 11:46:04 +1000
committerNeilBrown <neilb@suse.de>2010-07-06 12:07:07 +1000
commit7d2e6486e34180215e4859c3b342246dfc6c07a0 (patch)
tree9ec3ec035088063fa72d2f148b5951fc9ddc9738
parenta4e13010df574a1ce597efe9cb15ed6d6003b8bb (diff)
downloadmdadm-7d2e6486e34180215e4859c3b342246dfc6c07a0.tar.gz
mdadm-7d2e6486e34180215e4859c3b342246dfc6c07a0.tar.xz
mdadm-7d2e6486e34180215e4859c3b342246dfc6c07a0.zip
Add --test option to --re-add and similar
--test can be given in Manage mode. This can be used when there is an attempt to fail or remove 'faulty', 'failed' or 'detached' devices, or to re-add 'missing' devices. If no devices were failed, removed, or re-added, then mdadm will exit with status '2'. Signed-off-by: NeilBrown <neilb@suse.de>
-rw-r--r--Incremental.c4
-rw-r--r--Manage.c9
-rw-r--r--Monitor.c6
-rw-r--r--mdadm.c5
-rw-r--r--mdadm.h2
5 files changed, 17 insertions, 9 deletions
diff --git a/Incremental.c b/Incremental.c
index 7f67535..4f10769 100644
--- a/Incremental.c
+++ b/Incremental.c
@@ -900,7 +900,7 @@ int IncrementalRemove(char *devname, int verbose)
memset(&devlist, 0, sizeof(devlist));
devlist.devname = devname;
devlist.disposition = 'f';
- Manage_subdevs(ent->dev, mdfd, &devlist, verbose);
+ Manage_subdevs(ent->dev, mdfd, &devlist, verbose, 0);
devlist.disposition = 'r';
- return Manage_subdevs(ent->dev, mdfd, &devlist, verbose);
+ return Manage_subdevs(ent->dev, mdfd, &devlist, verbose, 0);
}
diff --git a/Manage.c b/Manage.c
index b4e3900..c9a3705 100644
--- a/Manage.c
+++ b/Manage.c
@@ -326,7 +326,7 @@ int Manage_resize(char *devname, int fd, long long size, int raid_disks)
}
int Manage_subdevs(char *devname, int fd,
- mddev_dev_t devlist, int verbose)
+ mddev_dev_t devlist, int verbose, int test)
{
/* do something to each dev.
* devmode can be
@@ -355,6 +355,7 @@ int Manage_subdevs(char *devname, int fd,
int ouuid[4];
int lfd = -1;
int sysfd = -1;
+ int count = 0; /* number of actions taken */
if (ioctl(fd, GET_ARRAY_INFO, &array)) {
fprintf(stderr, Name ": cannot get array info for %s\n",
@@ -684,6 +685,7 @@ int Manage_subdevs(char *devname, int fd,
ioctl(fd, ADD_NEW_DISK, &disc) == 0) {
if (verbose >= 0)
fprintf(stderr, Name ": re-added %s\n", add_dev);
+ count++;
continue;
}
if (errno == ENOMEM || errno == EROFS) {
@@ -959,6 +961,7 @@ int Manage_subdevs(char *devname, int fd,
}
if (lfd >= 0)
close(lfd);
+ count++;
if (verbose >= 0)
fprintf(stderr, Name ": hot removed %s from %s\n",
dnprintable, devname);
@@ -978,14 +981,16 @@ int Manage_subdevs(char *devname, int fd,
if (sysfd >= 0)
close(sysfd);
sysfd = -1;
+ count++;
if (verbose >= 0)
fprintf(stderr, Name ": set %s faulty in %s\n",
dnprintable, devname);
break;
}
}
+ if (test && count == 0)
+ return 2;
return 0;
-
}
int autodetect(void)
diff --git a/Monitor.c b/Monitor.c
index 8e82797..7af36ab 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -491,15 +491,15 @@ int Monitor(mddev_dev_t devlist,
sprintf(devname, "%d:%d", major(dev), minor(dev));
devlist.disposition = 'r';
- if (Manage_subdevs(st2->devname, fd2, &devlist, -1) == 0) {
+ if (Manage_subdevs(st2->devname, fd2, &devlist, -1, 0) == 0) {
devlist.disposition = 'a';
- if (Manage_subdevs(st->devname, fd1, &devlist, -1) == 0) {
+ if (Manage_subdevs(st->devname, fd1, &devlist, -1, 0) == 0) {
alert("MoveSpare", st->devname, st2->devname, mailaddr, mailfrom, alert_cmd, dosyslog);
close(fd1);
close(fd2);
break;
}
- else Manage_subdevs(st2->devname, fd2, &devlist, -1);
+ else Manage_subdevs(st2->devname, fd2, &devlist, -1, 0);
}
}
close(fd1);
diff --git a/mdadm.c b/mdadm.c
index 770fdfd..9504af6 100644
--- a/mdadm.c
+++ b/mdadm.c
@@ -796,6 +796,9 @@ int main(int argc, char *argv[])
}
runstop = -1;
continue;
+ case O(MANAGE,'t'):
+ test = 1;
+ continue;
case O(MISC,'Q'):
case O(MISC,'D'):
@@ -1064,7 +1067,7 @@ int main(int argc, char *argv[])
rv = Manage_ro(devlist->devname, mdfd, readonly);
if (!rv && devs_found>1)
rv = Manage_subdevs(devlist->devname, mdfd,
- devlist->next, verbose-quiet);
+ devlist->next, verbose-quiet, test);
if (!rv && readonly < 0)
rv = Manage_ro(devlist->devname, mdfd, readonly);
if (!rv && runstop)
diff --git a/mdadm.h b/mdadm.h
index d15e73e..c5062ea 100644
--- a/mdadm.h
+++ b/mdadm.h
@@ -769,7 +769,7 @@ extern int Manage_ro(char *devname, int fd, int readonly);
extern int Manage_runstop(char *devname, int fd, int runstop, int quiet);
extern int Manage_resize(char *devname, int fd, long long size, int raid_disks);
extern int Manage_subdevs(char *devname, int fd,
- mddev_dev_t devlist, int verbose);
+ mddev_dev_t devlist, int verbose, int test);
extern int autodetect(void);
extern int Grow_Add_device(char *devname, int fd, char *newdev);
extern int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int write_behind, int force);