diff options
author | NeilBrown <neilb@suse.de> | 2013-07-01 05:28:13 +0200 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2013-07-01 05:28:13 +0200 |
commit | efc67e8e9fe430d5833236f16ea287ef363dadc5 (patch) | |
tree | 4da51e5aa6580aa3ae63eaf318fe16d93ad59163 /sysfs.c | |
parent | revert-reshape: make sure reshape_position is acceptable. (diff) | |
download | mdadm-efc67e8e9fe430d5833236f16ea287ef363dadc5.tar.xz mdadm-efc67e8e9fe430d5833236f16ea287ef363dadc5.zip |
New function: sysfs_wait
We have several places that wait for activity on a sysfs
file. Combine most of these into a single 'sysfs_wait' function.
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'sysfs.c')
-rw-r--r-- | sysfs.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -844,3 +844,32 @@ int sysfs_freeze_array(struct mdinfo *sra) return 0; return 1; } + +int sysfs_wait(int fd, int *msec) +{ + /* Wait up to '*msec' for fd to have an exception condition. + * if msec == NULL, wait indefinitely. + */ + fd_set fds; + int n; + FD_ZERO(&fds); + FD_SET(fd, &fds); + if (msec == NULL) + n = select(fd+1, NULL, NULL, &fds, NULL); + else if (*msec < 0) + n = 0; + else { + struct timeval start, end, tv; + gettimeofday(&start, NULL); + if (*msec < 1000) + tv.tv_usec = (*msec)*1000; + else + tv.tv_sec = (*msec)/1000; + n = select(fd+1, NULL, NULL, &fds, &tv); + gettimeofday(&end, NULL); + end.tv_sec -= start.tv_sec; + *msec -= (end.tv_sec * 1000 + end.tv_usec/1000 + - start.tv_usec/100) + 1; + } + return n; +} |