[PATCH] md: complete conversion of md to use kthreads

There are a few loose ends following the conversion of md to use kthreads:

- Some fields in mdk_thread_t that aren't needed (kthreads does it's own
  completion and manages it's own name).

- thread->run is now never NULL, so no need to check

- Some tests for signal_pending that aren't needed (As we don't use signals
  to stop threads any more)

- Some flush_signals are not needed

- Some waits are interruptible and don't need to be.

Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
NeilBrown 2005-11-08 21:39:43 -08:00 committed by Linus Torvalds
parent fd9d49cac4
commit 787453c239
2 changed files with 10 additions and 25 deletions

View File

@ -3424,21 +3424,17 @@ static int md_thread(void * arg)
*/ */
allow_signal(SIGKILL); allow_signal(SIGKILL);
complete(thread->event);
while (!kthread_should_stop()) { while (!kthread_should_stop()) {
void (*run)(mddev_t *);
wait_event_interruptible_timeout(thread->wqueue, wait_event_timeout(thread->wqueue,
test_bit(THREAD_WAKEUP, &thread->flags) test_bit(THREAD_WAKEUP, &thread->flags)
|| kthread_should_stop(), || kthread_should_stop(),
thread->timeout); thread->timeout);
try_to_freeze(); try_to_freeze();
clear_bit(THREAD_WAKEUP, &thread->flags); clear_bit(THREAD_WAKEUP, &thread->flags);
run = thread->run; thread->run(thread->mddev);
if (run)
run(thread->mddev);
} }
return 0; return 0;
@ -3457,7 +3453,6 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev,
const char *name) const char *name)
{ {
mdk_thread_t *thread; mdk_thread_t *thread;
struct completion event;
thread = kmalloc(sizeof(mdk_thread_t), GFP_KERNEL); thread = kmalloc(sizeof(mdk_thread_t), GFP_KERNEL);
if (!thread) if (!thread)
@ -3466,18 +3461,14 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev,
memset(thread, 0, sizeof(mdk_thread_t)); memset(thread, 0, sizeof(mdk_thread_t));
init_waitqueue_head(&thread->wqueue); init_waitqueue_head(&thread->wqueue);
init_completion(&event);
thread->event = &event;
thread->run = run; thread->run = run;
thread->mddev = mddev; thread->mddev = mddev;
thread->name = name;
thread->timeout = MAX_SCHEDULE_TIMEOUT; thread->timeout = MAX_SCHEDULE_TIMEOUT;
thread->tsk = kthread_run(md_thread, thread, name, mdname(thread->mddev)); thread->tsk = kthread_run(md_thread, thread, name, mdname(thread->mddev));
if (IS_ERR(thread->tsk)) { if (IS_ERR(thread->tsk)) {
kfree(thread); kfree(thread);
return NULL; return NULL;
} }
wait_for_completion(&event);
return thread; return thread;
} }
@ -3941,9 +3932,7 @@ static void md_do_sync(mddev_t *mddev)
mddev->curr_resync = 2; mddev->curr_resync = 2;
try_again: try_again:
if (signal_pending(current) || if (kthread_should_stop()) {
kthread_should_stop()) {
flush_signals(current);
set_bit(MD_RECOVERY_INTR, &mddev->recovery); set_bit(MD_RECOVERY_INTR, &mddev->recovery);
goto skip; goto skip;
} }
@ -3963,9 +3952,8 @@ static void md_do_sync(mddev_t *mddev)
* time 'round when curr_resync == 2 * time 'round when curr_resync == 2
*/ */
continue; continue;
prepare_to_wait(&resync_wait, &wq, TASK_INTERRUPTIBLE); prepare_to_wait(&resync_wait, &wq, TASK_UNINTERRUPTIBLE);
if (!signal_pending(current) && if (!kthread_should_stop() &&
!kthread_should_stop() &&
mddev2->curr_resync >= mddev->curr_resync) { mddev2->curr_resync >= mddev->curr_resync) {
printk(KERN_INFO "md: delaying resync of %s" printk(KERN_INFO "md: delaying resync of %s"
" until %s has finished resync (they" " until %s has finished resync (they"
@ -4074,13 +4062,12 @@ static void md_do_sync(mddev_t *mddev)
} }
if (signal_pending(current) || kthread_should_stop()) { if (kthread_should_stop()) {
/* /*
* got a signal, exit. * got a signal, exit.
*/ */
printk(KERN_INFO printk(KERN_INFO
"md: md_do_sync() got signal ... exiting\n"); "md: md_do_sync() got signal ... exiting\n");
flush_signals(current);
set_bit(MD_RECOVERY_INTR, &mddev->recovery); set_bit(MD_RECOVERY_INTR, &mddev->recovery);
goto out; goto out;
} }
@ -4102,7 +4089,7 @@ static void md_do_sync(mddev_t *mddev)
if (currspeed > sysctl_speed_limit_min) { if (currspeed > sysctl_speed_limit_min) {
if ((currspeed > sysctl_speed_limit_max) || if ((currspeed > sysctl_speed_limit_max) ||
!is_mddev_idle(mddev)) { !is_mddev_idle(mddev)) {
msleep_interruptible(250); msleep(250);
goto repeat; goto repeat;
} }
} }

View File

@ -334,10 +334,8 @@ typedef struct mdk_thread_s {
mddev_t *mddev; mddev_t *mddev;
wait_queue_head_t wqueue; wait_queue_head_t wqueue;
unsigned long flags; unsigned long flags;
struct completion *event;
struct task_struct *tsk; struct task_struct *tsk;
unsigned long timeout; unsigned long timeout;
const char *name;
} mdk_thread_t; } mdk_thread_t;
#define THREAD_WAKEUP 0 #define THREAD_WAKEUP 0