mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-18 10:04:20 +03:00
daemon-server: handle reaping threads better
Avoid sleeping in pselect when thread missed reap() handling. This speedup handling of daemon shutdown sequences.
This commit is contained in:
parent
fe4f83171d
commit
1f17b1c565
@ -551,9 +551,14 @@ static void _reap(daemon_state s, int waiting)
|
|||||||
|
|
||||||
while (ts) {
|
while (ts) {
|
||||||
if (waiting || !ts->active) {
|
if (waiting || !ts->active) {
|
||||||
if (ts->client.thread_id &&
|
if (ts->client.thread_id) {
|
||||||
(errno = pthread_join(ts->client.thread_id, &rv)))
|
if ((errno = pthread_kill(ts->client.thread_id, SIGTERM)) &&
|
||||||
|
(errno != ESRCH))
|
||||||
|
ERROR(&s, "pthread_kill failed for pid %ld",
|
||||||
|
(long)ts->client.thread_id);
|
||||||
|
if ((errno = pthread_join(ts->client.thread_id, &rv)))
|
||||||
ERROR(&s, "pthread_join failed: %s", strerror(errno));
|
ERROR(&s, "pthread_join failed: %s", strerror(errno));
|
||||||
|
}
|
||||||
last->next = ts->next;
|
last->next = ts->next;
|
||||||
free(ts);
|
free(ts);
|
||||||
} else
|
} else
|
||||||
@ -659,19 +664,13 @@ void daemon_start(daemon_state s)
|
|||||||
if (sigprocmask(SIG_SETMASK, NULL, &old_set))
|
if (sigprocmask(SIG_SETMASK, NULL, &old_set))
|
||||||
perror("sigprocmask error");
|
perror("sigprocmask error");
|
||||||
|
|
||||||
while (!failed) {
|
while (!failed && !_shutdown_requested) {
|
||||||
_reset_timeout(s);
|
_reset_timeout(s);
|
||||||
FD_ZERO(&in);
|
FD_ZERO(&in);
|
||||||
FD_SET(s.socket_fd, &in);
|
FD_SET(s.socket_fd, &in);
|
||||||
|
|
||||||
if (sigprocmask(SIG_SETMASK, &new_set, NULL))
|
if (sigprocmask(SIG_SETMASK, &new_set, NULL))
|
||||||
perror("sigprocmask error");
|
perror("sigprocmask error");
|
||||||
if (_shutdown_requested && !s.threads->next) {
|
|
||||||
if (sigprocmask(SIG_SETMASK, &old_set, NULL))
|
|
||||||
perror("sigprocmask error");
|
|
||||||
INFO(&s, "%s shutdown requested", s.name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ret = pselect(s.socket_fd + 1, &in, NULL, NULL, _get_timeout(s), &old_set);
|
ret = pselect(s.socket_fd + 1, &in, NULL, NULL, _get_timeout(s), &old_set);
|
||||||
if (sigprocmask(SIG_SETMASK, &old_set, NULL))
|
if (sigprocmask(SIG_SETMASK, &old_set, NULL))
|
||||||
perror("sigprocmask error");
|
perror("sigprocmask error");
|
||||||
@ -679,6 +678,7 @@ void daemon_start(daemon_state s)
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if ((errno != EINTR) && (errno != EAGAIN))
|
if ((errno != EINTR) && (errno != EAGAIN))
|
||||||
perror("select error");
|
perror("select error");
|
||||||
|
_reap(s, 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -698,6 +698,9 @@ void daemon_start(daemon_state s)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_shutdown_requested)
|
||||||
|
INFO(&s, "%s shutdown requested", s.name);
|
||||||
|
|
||||||
INFO(&s, "%s waiting for client threads to finish", s.name);
|
INFO(&s, "%s waiting for client threads to finish", s.name);
|
||||||
_reap(s, 1);
|
_reap(s, 1);
|
||||||
out:
|
out:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user