提交 a6fb0934 编写于 作者: N NeilBrown 提交者: Linus Torvalds

[PATCH] md: use kthread infrastructure in md

Switch MD to use the kthread infrastructure, to simplify the code and get rid
of tasklist_lock abuse in md_unregister_thread.

Also don't flush signals in md_thread, as the called thread will always do
that.
Signed-off-by: NChristoph Hellwig <hch@lst.de>
Signed-off-by: NNeil Brown <neilb@cse.unsw.edu.au>
Signed-off-by: NAndrew Morton <akpm@osdl.org>
Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
上级 934ce7c8
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/config.h> #include <linux/config.h>
#include <linux/kthread.h>
#include <linux/linkage.h> #include <linux/linkage.h>
#include <linux/raid/md.h> #include <linux/raid/md.h>
#include <linux/raid/bitmap.h> #include <linux/raid/bitmap.h>
...@@ -3049,18 +3050,6 @@ static int md_thread(void * arg) ...@@ -3049,18 +3050,6 @@ static int md_thread(void * arg)
{ {
mdk_thread_t *thread = arg; mdk_thread_t *thread = arg;
lock_kernel();
/*
* Detach thread
*/
daemonize(thread->name, mdname(thread->mddev));
current->exit_signal = SIGCHLD;
allow_signal(SIGKILL);
thread->tsk = current;
/* /*
* md_thread is a 'system-thread', it's priority should be very * md_thread is a 'system-thread', it's priority should be very
* high. We avoid resource deadlocks individually in each * high. We avoid resource deadlocks individually in each
...@@ -3072,14 +3061,14 @@ static int md_thread(void * arg) ...@@ -3072,14 +3061,14 @@ static int md_thread(void * arg)
* bdflush, otherwise bdflush will deadlock if there are too * bdflush, otherwise bdflush will deadlock if there are too
* many dirty RAID5 blocks. * many dirty RAID5 blocks.
*/ */
unlock_kernel();
complete(thread->event); complete(thread->event);
while (thread->run) { while (!kthread_should_stop()) {
void (*run)(mddev_t *); void (*run)(mddev_t *);
wait_event_interruptible_timeout(thread->wqueue, wait_event_interruptible_timeout(thread->wqueue,
test_bit(THREAD_WAKEUP, &thread->flags), test_bit(THREAD_WAKEUP, &thread->flags)
|| kthread_should_stop(),
thread->timeout); thread->timeout);
try_to_freeze(); try_to_freeze();
...@@ -3088,11 +3077,8 @@ static int md_thread(void * arg) ...@@ -3088,11 +3077,8 @@ static int md_thread(void * arg)
run = thread->run; run = thread->run;
if (run) if (run)
run(thread->mddev); run(thread->mddev);
if (signal_pending(current))
flush_signals(current);
} }
complete(thread->event);
return 0; return 0;
} }
...@@ -3109,11 +3095,9 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, ...@@ -3109,11 +3095,9 @@ 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;
int ret;
struct completion event; struct completion event;
thread = (mdk_thread_t *) kmalloc thread = kmalloc(sizeof(mdk_thread_t), GFP_KERNEL);
(sizeof(mdk_thread_t), GFP_KERNEL);
if (!thread) if (!thread)
return NULL; return NULL;
...@@ -3126,8 +3110,8 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, ...@@ -3126,8 +3110,8 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev,
thread->mddev = mddev; thread->mddev = mddev;
thread->name = name; thread->name = name;
thread->timeout = MAX_SCHEDULE_TIMEOUT; thread->timeout = MAX_SCHEDULE_TIMEOUT;
ret = kernel_thread(md_thread, thread, 0); thread->tsk = kthread_run(md_thread, thread, mdname(thread->mddev));
if (ret < 0) { if (IS_ERR(thread->tsk)) {
kfree(thread); kfree(thread);
return NULL; return NULL;
} }
...@@ -3137,21 +3121,9 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev, ...@@ -3137,21 +3121,9 @@ mdk_thread_t *md_register_thread(void (*run) (mddev_t *), mddev_t *mddev,
void md_unregister_thread(mdk_thread_t *thread) void md_unregister_thread(mdk_thread_t *thread)
{ {
struct completion event;
init_completion(&event);
thread->event = &event;
/* As soon as ->run is set to NULL, the task could disappear,
* so we need to hold tasklist_lock until we have sent the signal
*/
dprintk("interrupting MD-thread pid %d\n", thread->tsk->pid); dprintk("interrupting MD-thread pid %d\n", thread->tsk->pid);
read_lock(&tasklist_lock);
thread->run = NULL; kthread_stop(thread->tsk);
send_sig(SIGKILL, thread->tsk, 1);
read_unlock(&tasklist_lock);
wait_for_completion(&event);
kfree(thread); kfree(thread);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册