mdstat.c (mdadm-4.1) | : | mdstat.c (mdadm-4.2) | ||
---|---|---|---|---|
skipping to change at line 138 | skipping to change at line 138 | |||
struct mdstat_ent *mdstat_read(int hold, int start) | struct mdstat_ent *mdstat_read(int hold, int start) | |||
{ | { | |||
FILE *f; | FILE *f; | |||
struct mdstat_ent *all, *rv, **end, **insert_here; | struct mdstat_ent *all, *rv, **end, **insert_here; | |||
char *line; | char *line; | |||
int fd; | int fd; | |||
if (hold && mdstat_fd != -1) { | if (hold && mdstat_fd != -1) { | |||
off_t offset = lseek(mdstat_fd, 0L, 0); | off_t offset = lseek(mdstat_fd, 0L, 0); | |||
if (offset == (off_t)-1) { | if (offset == (off_t)-1) { | |||
mdstat_close(); | ||||
return NULL; | return NULL; | |||
} | } | |||
fd = dup(mdstat_fd); | fd = dup(mdstat_fd); | |||
if (fd >= 0) | if (fd >= 0) | |||
f = fdopen(fd, "r"); | f = fdopen(fd, "r"); | |||
else | else | |||
return NULL; | return NULL; | |||
} else | } else | |||
f = fopen("/proc/mdstat", "r"); | f = fopen("/proc/mdstat", "r"); | |||
if (f == NULL) | if (f == NULL) | |||
skipping to change at line 195 | skipping to change at line 194 | |||
strcpy(ent->devnm, devnm); | strcpy(ent->devnm, devnm); | |||
for (w=dl_next(line); w!= line ; w=dl_next(w)) { | for (w=dl_next(line); w!= line ; w=dl_next(w)) { | |||
int l = strlen(w); | int l = strlen(w); | |||
char *eq; | char *eq; | |||
if (strcmp(w, "active") == 0) | if (strcmp(w, "active") == 0) | |||
ent->active = 1; | ent->active = 1; | |||
else if (strcmp(w, "inactive") == 0) { | else if (strcmp(w, "inactive") == 0) { | |||
ent->active = 0; | ent->active = 0; | |||
in_devs = 1; | in_devs = 1; | |||
} else if (strcmp(w, "bitmap:") == 0) { | ||||
/* We need to stop parsing here; | ||||
* otherwise, ent->raid_disks will be | ||||
* overwritten by the wrong value. | ||||
*/ | ||||
break; | ||||
} else if (ent->active > 0 && | } else if (ent->active > 0 && | |||
ent->level == NULL && | ent->level == NULL && | |||
w[0] != '(' /*readonly*/) { | w[0] != '(' /*readonly*/) { | |||
ent->level = xstrdup(w); | ent->level = xstrdup(w); | |||
in_devs = 1; | in_devs = 1; | |||
} else if (in_devs && strcmp(w, "blocks") == 0) | } else if (in_devs && strcmp(w, "blocks") == 0) | |||
in_devs = 0; | in_devs = 0; | |||
else if (in_devs) { | else if (in_devs) { | |||
char *ep = strchr(w, '['); | char *ep = strchr(w, '['); | |||
ent->devcnt += | ent->devcnt += | |||
skipping to change at line 260 | skipping to change at line 265 | |||
ent->resync = 2; | ent->resync = 2; | |||
if (strncmp(w, "recovery", 8) == 0) | if (strncmp(w, "recovery", 8) == 0) | |||
ent->resync = 0; | ent->resync = 0; | |||
if (strncmp(w, "check", 5) == 0) | if (strncmp(w, "check", 5) == 0) | |||
ent->resync = 3; | ent->resync = 3; | |||
if (l > 8 && strcmp(w+l-8, "=DELAYED") == 0) | if (l > 8 && strcmp(w+l-8, "=DELAYED") == 0) | |||
ent->percent = RESYNC_DELAYED; | ent->percent = RESYNC_DELAYED; | |||
if (l > 8 && strcmp(w+l-8, "=PENDING") == 0) | if (l > 8 && strcmp(w+l-8, "=PENDING") == 0) | |||
ent->percent = RESYNC_PENDING; | ent->percent = RESYNC_PENDING; | |||
if (l > 7 && strcmp(w+l-7, "=REMOTE") == 0) | ||||
ent->percent = RESYNC_REMOTE; | ||||
} else if (ent->percent == RESYNC_NONE && | } else if (ent->percent == RESYNC_NONE && | |||
w[0] >= '0' && | w[0] >= '0' && | |||
w[0] <= '9' && | w[0] <= '9' && | |||
w[l-1] == '%') { | w[l-1] == '%') { | |||
ent->percent = atoi(w); | ent->percent = atoi(w); | |||
} | } | |||
} | } | |||
if (insert_here && (*insert_here)) { | if (insert_here && (*insert_here)) { | |||
ent->next = *insert_here; | ent->next = *insert_here; | |||
*insert_here = ent; | *insert_here = ent; | |||
skipping to change at line 304 | skipping to change at line 311 | |||
return rv; | return rv; | |||
} | } | |||
void mdstat_close(void) | void mdstat_close(void) | |||
{ | { | |||
if (mdstat_fd >= 0) | if (mdstat_fd >= 0) | |||
close(mdstat_fd); | close(mdstat_fd); | |||
mdstat_fd = -1; | mdstat_fd = -1; | |||
} | } | |||
void mdstat_wait(int seconds) | /* | |||
* function: mdstat_wait | ||||
* Description: Function waits for event on mdstat. | ||||
* Parameters: | ||||
* seconds - timeout for waiting | ||||
* Returns: | ||||
* > 0 - detected event | ||||
* 0 - timeout | ||||
* < 0 - detected error | ||||
*/ | ||||
int mdstat_wait(int seconds) | ||||
{ | { | |||
fd_set fds; | fd_set fds; | |||
struct timeval tm; | struct timeval tm; | |||
int maxfd = 0; | int maxfd = 0; | |||
FD_ZERO(&fds); | FD_ZERO(&fds); | |||
if (mdstat_fd >= 0) { | if (mdstat_fd >= 0) { | |||
FD_SET(mdstat_fd, &fds); | FD_SET(mdstat_fd, &fds); | |||
maxfd = mdstat_fd; | maxfd = mdstat_fd; | |||
} | } else | |||
return -1; | ||||
tm.tv_sec = seconds; | tm.tv_sec = seconds; | |||
tm.tv_usec = 0; | tm.tv_usec = 0; | |||
select(maxfd + 1, NULL, NULL, &fds, &tm); | ||||
return select(maxfd + 1, NULL, NULL, &fds, &tm); | ||||
} | } | |||
void mdstat_wait_fd(int fd, const sigset_t *sigmask) | void mdstat_wait_fd(int fd, const sigset_t *sigmask) | |||
{ | { | |||
fd_set fds, rfds; | fd_set fds, rfds; | |||
int maxfd = 0; | int maxfd = 0; | |||
FD_ZERO(&fds); | FD_ZERO(&fds); | |||
FD_ZERO(&rfds); | FD_ZERO(&rfds); | |||
if (mdstat_fd >= 0) | if (mdstat_fd >= 0) | |||
End of changes. 6 change blocks. | ||||
4 lines changed or deleted | 24 lines changed or added |