* 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
* 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 [===>....],
f = fopen("/proc/mdstat", "r");
if (f == NULL)
return NULL;
+ else
+ fcntl(fileno(f), F_SETFD, FD_CLOEXEC);
all = NULL;
end = &all;
ent->dev = strdup(line);
ent->devnum = devnum;
-
+
for (w=dl_next(line); w!= line ; w=dl_next(w)) {
int l = strlen(w);
char *eq;
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);
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,
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;
+}