From patchwork Wed Nov 22 06:20:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tang.junhui@zte.com.cn X-Patchwork-Id: 10069819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 767336038F for ; Wed, 22 Nov 2017 06:21:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6E04029989 for ; Wed, 22 Nov 2017 06:21:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60F9D29B7E; Wed, 22 Nov 2017 06:21:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF70929989 for ; Wed, 22 Nov 2017 06:21:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751296AbdKVGVg (ORCPT ); Wed, 22 Nov 2017 01:21:36 -0500 Received: from out1.zte.com.cn ([202.103.147.172]:40250 "EHLO mxct.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751368AbdKVGUj (ORCPT ); Wed, 22 Nov 2017 01:20:39 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id D8B6FA56BD21461B156D; Wed, 22 Nov 2017 14:20:35 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id vAM6KHX3032165; Wed, 22 Nov 2017 14:20:17 +0800 (GMT-8) (envelope-from tang.junhui@zte.com.cn) Received: from localhost.localdomain ([10.118.202.203]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2017112214202324-2218930 ; Wed, 22 Nov 2017 14:20:23 +0800 From: tang.junhui@zte.com.cn To: colyli@suse.de, mlyle@lyle.org Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, tang.junhui@zte.com.cn Subject: [PATCH v2] bcache: stop writeback thread after detaching Date: Wed, 22 Nov 2017 14:20:13 +0800 Message-Id: <1511331613-23140-1-git-send-email-tang.junhui@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2017-11-22 14:20:23, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2017-11-22 14:20:09, Serialize complete at 2017-11-22 14:20:09 X-MAIL: mse01.zte.com.cn vAM6KHX3032165 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Tang Junhui Currently, when a cached device detaching from cache, writeback thread is not stopped, and writeback_rate_update work is not canceled. For example, after bellow command: echo 1 >/sys/block/sdb/bcache/detach you can still see the writeback thread. Then you attach the device to the cache again, bcache will create another writeback thread, for example, after bellow command: echo ba0fb5cd-658a-4533-9806-6ce166d883b9 > /sys/block/sdb/bcache/attach then you will see 2 writeback threads. This patch stops writeback thread and cancels writeback_rate_update work when cached device detaching from cache. Compare with patch v1, this v2 patch moves code down into the register lock for safety in case of any future changes as Coly and mike suggested. Signed-off-by: Tang Junhui Reviewed-by: Michael Lyle --- drivers/md/bcache/super.c | 6 ++++++ 1 file changed, 6 insertions(+) mode change 100644 => 100755 drivers/md/bcache/super.c diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c old mode 100644 new mode 100755 index 8352fad..1c5136e --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -893,6 +893,12 @@ static void cached_dev_detach_finish(struct work_struct *w) mutex_lock(&bch_register_lock); + cancel_delayed_work_sync(&dc->writeback_rate_update); + if (!IS_ERR_OR_NULL(dc->writeback_thread)) { + kthread_stop(dc->writeback_thread); + dc->writeback_thread = NULL; + } + memset(&dc->sb.set_uuid, 0, 16); SET_BDEV_STATE(&dc->sb, BDEV_STATE_NONE);