]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
--wait or -W will wait for resync activity to finish on the given devices.
authorNeil Brown <neilb@suse.de>
Thu, 14 Dec 2006 06:31:22 +0000 (17:31 +1100)
committerNeil Brown <neilb@suse.de>
Thu, 14 Dec 2006 06:31:22 +0000 (17:31 +1100)
ChangeLog
Monitor.c
ReadMe.c
mdadm.8
mdadm.c
mdadm.h

index bd3424ef90fd6e7270d5ca8a41ce25c2fac99758..d1e0eb03685b9030d14dcf1f743bc8042a56b963 100644 (file)
--- 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
index 315fee2548cb03a8b3459b49428dcad7d24bdeed..5091c51b3c7d091bd044fa35c7b555288e6d3f65 100644 (file)
--- 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);
+       }
+}
index 1554a9a241f682252c1efbe6c485193227b04ed7..739b36601cfacf93ae255006c6a995ac7526a0e2 100644 (file)
--- 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 274609c17180676c953473413faa455b9fb23815..b618f5a671a2adaae1819f0ad4e16042cddb2d0b 100644 (file)
--- 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 41360c4813afa403a234f8e89f1879482dd44fe0..5fb1b8de503efb36725dd5acf88cac0790baf090 100644 (file)
--- 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 bfc2138884d2bca6b467a391de32b65ea40f69be..f1768a53c621de1c8f4662b788021b5056093278 100644 (file)
--- 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,