From b90c0e9a12090c435f23da8378b3436c93f77f2f Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Thu, 14 Dec 2006 17:31:22 +1100 Subject: [PATCH] --wait or -W will wait for resync activity to finish on the given devices. --- ChangeLog | 2 ++ Monitor.c | 35 +++++++++++++++++++++++++++++++++++ ReadMe.c | 7 +++++-- mdadm.8 | 8 ++++++++ mdadm.c | 5 ++++- mdadm.h | 1 + 6 files changed, 55 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index bd3424ef..d1e0eb03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17,6 +17,8 @@ Changes Prior to this release kernel, and it not reset when the reshape finishes. - Change 'Device Size' to 'Used Dev Size' because it only shows how much of each device is actually used, not how big they are. + - --wait or -W will wait for resync activity to finish on the given + devices. Changes Prior to 2.5.6 release - Fix bug which meant "bitmap=xxx" in mdadm.conf was not handled diff --git a/Monitor.c b/Monitor.c index 315fee25..5091c51b 100644 --- a/Monitor.c +++ b/Monitor.c @@ -553,3 +553,38 @@ static void alert(char *event, char *dev, char *disc, char *mailaddr, char *mail syslog(priority, "%s event detected on md device %s", event, dev); } } + +/* Not really Monitor but ... */ +int Wait(char *dev) +{ + struct stat stb; + int devnum; + int rv = 1; + + if (stat(dev, &stb) != 0) { + fprintf(stderr, Name ": Cannot find %s: %s\n", dev, + strerror(errno)); + return 2; + } + if (major(stb.st_rdev) == MD_MAJOR) + devnum = minor(stb.st_rdev); + else + devnum = -minor(stb.st_rdev)/16; + + while(1) { + struct mdstat_ent *ms = mdstat_read(1, 0); + struct mdstat_ent *e; + + for (e=ms ; e; e=e->next) + if (e->devnum == devnum) + break; + + if (!e || e->percent < 0) { + free_mdstat(ms); + return rv; + } + free(ms); + rv = 0; + mdstat_wait(5); + } +} diff --git a/ReadMe.c b/ReadMe.c index 1554a9a2..739b3660 100644 --- a/ReadMe.c +++ b/ReadMe.c @@ -91,8 +91,8 @@ char Version[] = Name " - v2.5.6 - 9 November 2006\n"; * At the time if writing, there is only minimal support. */ -char short_options[]="-ABCDEFGQhVXvqbc:i:l:p:m:n:x:u:c:d:z:U:sarfRSow1tye:"; -char short_bitmap_auto_options[]="-ABCDEFGQhVXvqb:c:i:l:p:m:n:x:u:c:d:z:U:sa:rfRSow1tye:"; +char short_options[]="-ABCDEFGQhVXWvqbc:i:l:p:m:n:x:u:c:d:z:U:sarfRSow1tye:"; +char short_bitmap_auto_options[]="-ABCDEFGQhVXWvqb:c:i:l:p:m:n:x:u:c:d:z:U:sa:rfRSow1tye:"; struct option long_options[] = { {"manage", 0, 0, '@'}, @@ -160,6 +160,7 @@ struct option long_options[] = { {"readonly", 0, 0, 'o'}, {"readwrite", 0, 0, 'w'}, {"no-degraded",0,0, NoDegraded }, + {"wait", 0, 0, 'W'}, /* For Detail/Examine */ {"brief", 0, 0, 'b'}, @@ -296,6 +297,7 @@ char OptionHelp[] = " --readonly -o : mark array as readonly\n" " --readwrite -w : mark array as readwrite\n" " --zero-superblock : erase the MD superblock from a device.\n" +" --wait -W : wait for recovery/resync/reshape to finish.\n" ; */ @@ -459,6 +461,7 @@ char Help_misc[] = " --readonly -o : mark array as readonly\n" " --readwrite -w : mark array as readwrite\n" " --test -t : exit status 0 if ok, 1 if degrade, 2 if dead, 4 if missing\n" +" --wait -W : wait for resync/rebuild/recovery to finish\n" ; char Help_monitor[] = diff --git a/mdadm.8 b/mdadm.8 index 274609c1..b618f5a6 100644 --- a/mdadm.8 +++ b/mdadm.8 @@ -931,6 +931,14 @@ the exit status of .I mdadm is set to reflect the status of the device. +.TP +.BR -W ", " --wait +For each md device given, wait for any resync, recovery, or reshape +activity to finish before returning. +.I mdadm +will return with success if it actually waited for every device +listed, otherwise it will return failure. + .SH For Monitor mode: .TP .BR -m ", " --mail diff --git a/mdadm.c b/mdadm.c index 41360c48..5fb1b8de 100644 --- a/mdadm.c +++ b/mdadm.c @@ -201,6 +201,7 @@ int main(int argc, char *argv[]) case 'S': case 'o': case 'w': + case 'W': case 'K': if (!mode) newmode = MISC; break; } if (mode && newmode == mode) { @@ -742,6 +743,7 @@ int main(int argc, char *argv[]) case O(MISC,'X'): case O(MISC,'o'): case O(MISC,'w'): + case O(MISC,'W'): if (devmode && devmode != opt && (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) { fprintf(stderr, Name ": --examine/-E cannot be given with -%c\n", @@ -1138,7 +1140,6 @@ int main(int argc, char *argv[]) bitmap_file, bitmap_chunk, write_behind, delay); break; case MISC: - if (devmode == 'E') { if (devlist == NULL && !scan) { fprintf(stderr, Name ": No devices to examine\n"); @@ -1219,6 +1220,8 @@ int main(int argc, char *argv[]) rv |= Query(dv->devname); continue; case 'X': rv |= ExamineBitmap(dv->devname, brief, ss); continue; + case 'W': + rv |= Wait(dv->devname); continue; } mdfd = open_mddev(dv->devname, 1); if (mdfd>=0) { diff --git a/mdadm.h b/mdadm.h index bfc21388..f1768a53 100644 --- a/mdadm.h +++ b/mdadm.h @@ -421,6 +421,7 @@ extern int Monitor(mddev_dev_t devlist, int dosyslog, int test, char *pidfile); extern int Kill(char *dev, int force, int quiet); +extern int Wait(char *dev); extern int CreateBitmap(char *filename, int force, char uuid[16], unsigned long chunksize, unsigned long daemon_sleep, -- 2.39.2