Selaa lähdekoodia

raid5-cache: suspend reclaim thread instead of shutdown

There is mechanism to suspend a kernel thread. Use it instead of playing
create/destroy game.

Signed-off-by: Shaohua Li <shli@fb.com>
Reviewed-by: NeilBrown <neilb@suse.de>
Cc: Song Liu <songliubraving@fb.com>
Shaohua Li 8 vuotta sitten
vanhempi
commit
ce1ccd079f
2 muutettua tiedostoa jossa 8 lisäystä ja 14 poistoa
  1. 3 1
      drivers/md/md.c
  2. 5 13
      drivers/md/raid5-cache.c

+ 3 - 1
drivers/md/md.c

@@ -7187,10 +7187,12 @@ static int md_thread(void *arg)
 		wait_event_interruptible_timeout
 		wait_event_interruptible_timeout
 			(thread->wqueue,
 			(thread->wqueue,
 			 test_bit(THREAD_WAKEUP, &thread->flags)
 			 test_bit(THREAD_WAKEUP, &thread->flags)
-			 || kthread_should_stop(),
+			 || kthread_should_stop() || kthread_should_park(),
 			 thread->timeout);
 			 thread->timeout);
 
 
 		clear_bit(THREAD_WAKEUP, &thread->flags);
 		clear_bit(THREAD_WAKEUP, &thread->flags);
+		if (kthread_should_park())
+			kthread_parkme();
 		if (!kthread_should_stop())
 		if (!kthread_should_stop())
 			thread->run(thread);
 			thread->run(thread);
 	}
 	}

+ 5 - 13
drivers/md/raid5-cache.c

@@ -19,6 +19,7 @@
 #include <linux/raid/md_p.h>
 #include <linux/raid/md_p.h>
 #include <linux/crc32c.h>
 #include <linux/crc32c.h>
 #include <linux/random.h>
 #include <linux/random.h>
+#include <linux/kthread.h>
 #include "md.h"
 #include "md.h"
 #include "raid5.h"
 #include "raid5.h"
 #include "bitmap.h"
 #include "bitmap.h"
@@ -1437,23 +1438,14 @@ void r5l_quiesce(struct r5l_log *log, int state)
 	struct mddev *mddev;
 	struct mddev *mddev;
 	if (!log || state == 2)
 	if (!log || state == 2)
 		return;
 		return;
-	if (state == 0) {
-		/*
-		 * This is a special case for hotadd. In suspend, the array has
-		 * no journal. In resume, journal is initialized as well as the
-		 * reclaim thread.
-		 */
-		if (log->reclaim_thread)
-			return;
-		log->reclaim_thread = md_register_thread(r5l_reclaim_thread,
-					log->rdev->mddev, "reclaim");
-		log->reclaim_thread->timeout = R5C_RECLAIM_WAKEUP_INTERVAL;
-	} else if (state == 1) {
+	if (state == 0)
+		kthread_unpark(log->reclaim_thread->tsk);
+	else if (state == 1) {
 		/* make sure r5l_write_super_and_discard_space exits */
 		/* make sure r5l_write_super_and_discard_space exits */
 		mddev = log->rdev->mddev;
 		mddev = log->rdev->mddev;
 		wake_up(&mddev->sb_wait);
 		wake_up(&mddev->sb_wait);
+		kthread_park(log->reclaim_thread->tsk);
 		r5l_wake_reclaim(log, MaxSector);
 		r5l_wake_reclaim(log, MaxSector);
-		md_unregister_thread(&log->reclaim_thread);
 		r5l_do_reclaim(log);
 		r5l_do_reclaim(log);
 	}
 	}
 }
 }