mdmonitor: set small delay once

If mdmonitor is awakened by event, set small delay once
to deal with udev and mdadm.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
This commit is contained in:
Blazej Kucman 2020-09-09 10:31:19 +02:00 committed by Jes Sorensen
parent 007087d089
commit cab9c67d46
3 changed files with 29 additions and 5 deletions

View File

@ -128,6 +128,7 @@ int Monitor(struct mddev_dev *devlist,
char *mailfrom;
struct alert_info info;
struct mddev_ident *mdlist;
int delay_for_event = c->delay;
if (!mailaddr) {
mailaddr = conf_get_mailaddr();
@ -249,7 +250,18 @@ int Monitor(struct mddev_dev *devlist,
break;
}
else {
mdstat_wait(c->delay);
int wait_result = mdstat_wait(delay_for_event);
/*
* If mdmonitor is awaken by event, set small delay once
* to deal with udev and mdadm.
*/
if (wait_result != 0) {
if (c->delay > 5)
delay_for_event = 5;
} else
delay_for_event = c->delay;
mdstat_close();
}
}

View File

@ -628,7 +628,7 @@ struct mdstat_ent {
extern struct mdstat_ent *mdstat_read(int hold, int start);
extern void mdstat_close(void);
extern void free_mdstat(struct mdstat_ent *ms);
extern void mdstat_wait(int seconds);
extern int mdstat_wait(int seconds);
extern void mdstat_wait_fd(int fd, const sigset_t *sigmask);
extern int mddev_busy(char *devnm);
extern struct mdstat_ent *mdstat_by_component(char *name);

View File

@ -302,7 +302,17 @@ void mdstat_close(void)
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;
struct timeval tm;
@ -312,10 +322,12 @@ void mdstat_wait(int seconds)
FD_SET(mdstat_fd, &fds);
maxfd = mdstat_fd;
} else
return;
return -1;
tm.tv_sec = seconds;
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)