]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - mdstat.c
Replace sysarray with mdinfo
[thirdparty/mdadm.git] / mdstat.c
index 7ef4443db26fe686e9110eea6e0b88765d04ada0..a8f7ce7576eb1d017acfe962a1dea48084cde5d2 100644 (file)
--- a/mdstat.c
+++ b/mdstat.c
@@ -2,7 +2,7 @@
  * mdstat - parse /proc/mdstat file. Part of:
  * mdadm - manage Linux "md" devices aka RAID arrays.
  *
- * Copyright (C) 2002 Neil Brown <neilb@cse.unsw.edu.au>
+ * Copyright (C) 2002-2006 Neil Brown <neilb@suse.de>
  *
  *
  *    This program is free software; you can redistribute it and/or modify
@@ -43,7 +43,7 @@
  *  read_ahead {not set|%d sectors}
  *  mdN : {in}active {(readonly)} raidX dev[%d]{(F)} ... %d blocks STATUS RESYNC
  *  ... Only initialised arrays listed
- *  unused: dev dev dev | <none>
+ *  unused devices: {dev dev ... | <none>}
  *
  * STATUS is personality dependant:
  *    linear:  %dk rounding
@@ -62,7 +62,7 @@
  *  mdN : {in}active {(read-only)} raidX dev[%d]{(F)} ...
  *       %d blocks STATUS
  *       RESYNC
- *  unused: dev dev .. | <none>
+ *  unused devices: {dev dev .. | <none>}
  *
  *  STATUS matches 0.90.0/2.2
  *  RESYNC includes [===>....],
@@ -114,6 +114,8 @@ struct mdstat_ent *mdstat_read(int hold, int start)
                f = fopen("/proc/mdstat", "r");
        if (f == NULL)
                return NULL;
+       else
+               fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
 
        all = NULL;
        end = &all;
@@ -159,7 +161,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
 
                ent->dev = strdup(line);
                ent->devnum = devnum;
-               
+
                for (w=dl_next(line); w!= line ; w=dl_next(w)) {
                        int l = strlen(w);
                        char *eq;
@@ -207,7 +209,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
                                   strncmp(w, "resync", 4)==0) {
                                ent->resync = 1;
                        } else if (ent->percent == -1 &&
-                                  w[0] >= '0' && 
+                                  w[0] >= '0' &&
                                   w[0] <= '9' &&
                                   w[l-1] == '%') {
                                ent->percent = atoi(w);
@@ -221,8 +223,10 @@ struct mdstat_ent *mdstat_read(int hold, int start)
                        end = &ent->next;
                }
        }
-       if (hold && mdstat_fd == -1)
+       if (hold && mdstat_fd == -1) {
                mdstat_fd = dup(fileno(f));
+               fcntl(mdstat_fd, F_SETFD, FD_CLOEXEC);
+       }
        fclose(f);
 
        /* If we might want to start array,
@@ -251,3 +255,15 @@ void mdstat_wait(int seconds)
        tm.tv_usec = 0;
        select(mdstat_fd >2 ? mdstat_fd+1:3, NULL, NULL, &fds, &tm);
 }
+
+int mddev_busy(int devnum)
+{
+       struct mdstat_ent *mdstat = mdstat_read(0, 0);
+       struct mdstat_ent *me;
+
+       for (me = mdstat ; me ; me = me->next)
+               if (me->devnum == devnum)
+                       break;
+       free_mdstat(mdstat);
+       return me != NULL;
+}