diff mbox series

[v2] bcache: release dc->writeback_lock properly in bch_writeback_thread()

Message ID 20180822180256.15600-1-colyli@suse.de (mailing list archive)
State New, archived
Headers show
Series [v2] bcache: release dc->writeback_lock properly in bch_writeback_thread() | expand

Commit Message

Coly Li Aug. 22, 2018, 6:02 p.m. UTC
From: Shan Hai <shan.hai@oracle.com>

The writeback thread would exit with a lock held when the cache device is
detached via sysfs interface, fix it by releasing the held lock before exiting
the while-loop.

Fixes: fadd94e05c02 (bcache: quit dc->writeback_thread when BCACHE_DEV_DETACHING is set)
Signed-off-by: Shan Hai <shan.hai@oracle.com>
Signed-off-by: Coly Li <colyli@suse.de>
Tested-by: Shenghui Wang <shhuiw@foxmail.com>
Cc: stable@vger.kernel.org #4.17+
---
Changelog:
v2: add Fixes tag by Coly Li.
v1: initial patch from Shan Hai.

 drivers/md/bcache/writeback.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Coly Li Aug. 22, 2018, 6:07 p.m. UTC | #1
On 2018/8/23 2:02 AM, Coly Li wrote:
> From: Shan Hai <shan.hai@oracle.com>
> 
> The writeback thread would exit with a lock held when the cache device is
> detached via sysfs interface, fix it by releasing the held lock before exiting
> the while-loop.
> 
> Fixes: fadd94e05c02 (bcache: quit dc->writeback_thread when BCACHE_DEV_DETACHING is set)
> Signed-off-by: Shan Hai <shan.hai@oracle.com>
> Signed-off-by: Coly Li <colyli@suse.de>
> Tested-by: Shenghui Wang <shhuiw@foxmail.com>
> Cc: stable@vger.kernel.org #4.17+
> ---
> Changelog:
> v2: add Fixes tag by Coly Li.
> v1: initial patch from Shan Hai.

Hi Jens,

Please pick this patch for your next pull request. The change from Shan
Hai fixes a real issue which is reported and lately verified by Shenghui
Wang.

Thanks in advance.

Coly Li

> 
>  drivers/md/bcache/writeback.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
> index 6be05bd7ca67..08c3a9f9676c 100644
> --- a/drivers/md/bcache/writeback.c
> +++ b/drivers/md/bcache/writeback.c
> @@ -685,8 +685,10 @@ static int bch_writeback_thread(void *arg)
>  			 * data on cache. BCACHE_DEV_DETACHING flag is set in
>  			 * bch_cached_dev_detach().
>  			 */
> -			if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags))
> +			if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags)) {
> +				up_write(&dc->writeback_lock);
>  				break;
> +			}
>  		}
>  
>  		up_write(&dc->writeback_lock);
>
Jens Axboe Aug. 22, 2018, 6:13 p.m. UTC | #2
On 8/22/18 12:07 PM, Coly Li wrote:
> On 2018/8/23 2:02 AM, Coly Li wrote:
>> From: Shan Hai <shan.hai@oracle.com>
>>
>> The writeback thread would exit with a lock held when the cache device is
>> detached via sysfs interface, fix it by releasing the held lock before exiting
>> the while-loop.
>>
>> Fixes: fadd94e05c02 (bcache: quit dc->writeback_thread when BCACHE_DEV_DETACHING is set)
>> Signed-off-by: Shan Hai <shan.hai@oracle.com>
>> Signed-off-by: Coly Li <colyli@suse.de>
>> Tested-by: Shenghui Wang <shhuiw@foxmail.com>
>> Cc: stable@vger.kernel.org #4.17+
>> ---
>> Changelog:
>> v2: add Fixes tag by Coly Li.
>> v1: initial patch from Shan Hai.
> 
> Hi Jens,
> 
> Please pick this patch for your next pull request. The change from Shan
> Hai fixes a real issue which is reported and lately verified by Shenghui
> Wang.

Applied - but I fixed up the commit message. Please keep lines at
72 characters for git commits.
diff mbox series

Patch

diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 6be05bd7ca67..08c3a9f9676c 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -685,8 +685,10 @@  static int bch_writeback_thread(void *arg)
 			 * data on cache. BCACHE_DEV_DETACHING flag is set in
 			 * bch_cached_dev_detach().
 			 */
-			if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags))
+			if (test_bit(BCACHE_DEV_DETACHING, &dc->disk.flags)) {
+				up_write(&dc->writeback_lock);
 				break;
+			}
 		}
 
 		up_write(&dc->writeback_lock);