1 From 3943b040f11ed0cc6d4585fd286a623ca8634547 Mon Sep 17 00:00:00 2001
2 From: Shan Hai <shan.hai@oracle.com>
3 Date: Thu, 23 Aug 2018 02:02:56 +0800
4 Subject: bcache: release dc->writeback_lock properly in bch_writeback_thread()
6 From: Shan Hai <shan.hai@oracle.com>
8 commit 3943b040f11ed0cc6d4585fd286a623ca8634547 upstream.
10 The writeback thread would exit with a lock held when the cache device
11 is detached via sysfs interface, fix it by releasing the held lock
12 before exiting the while-loop.
14 Fixes: fadd94e05c02 (bcache: quit dc->writeback_thread when BCACHE_DEV_DETACHING is set)
15 Signed-off-by: Shan Hai <shan.hai@oracle.com>
16 Signed-off-by: Coly Li <colyli@suse.de>
17 Tested-by: Shenghui Wang <shhuiw@foxmail.com>
18 Cc: stable@vger.kernel.org #4.17+
19 Signed-off-by: Jens Axboe <axboe@kernel.dk>
20 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23 drivers/md/bcache/writeback.c | 4 +++-
24 1 file changed, 3 insertions(+), 1 deletion(-)
26 --- a/drivers/md/bcache/writeback.c
27 +++ b/drivers/md/bcache/writeback.c
28 @@ -456,8 +456,10 @@ static int bch_writeback_thread(void *ar
29 * data on cache. BCACHE_DEV_DETACHING flag is set in
30 * bch_cached_dev_detach().
32 - if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags))
33 + if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags)) {
34 + up_write(&dc->writeback_lock);
39 up_write(&dc->writeback_lock);