From patchwork Mon Jan 8 20:21:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Lyle X-Patchwork-Id: 10150541 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 17B69602CA for ; Mon, 8 Jan 2018 20:22:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2294528903 for ; Mon, 8 Jan 2018 20:22:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DC07128947; Mon, 8 Jan 2018 20:22:15 +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,DKIM_SIGNED, DKIM_VALID,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 39CF528A4A for ; Mon, 8 Jan 2018 20:21:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757207AbeAHUVo (ORCPT ); Mon, 8 Jan 2018 15:21:44 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:46434 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934270AbeAHUVm (ORCPT ); Mon, 8 Jan 2018 15:21:42 -0500 Received: by mail-pg0-f66.google.com with SMTP id r2so6298704pgq.13 for ; Mon, 08 Jan 2018 12:21:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lyle-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QPekpFMx1ppUdRUpn5y8rEdwicf/Cm9W+uOumWzWxMs=; b=iahN1vt8/SSIP4J7KDXqyB5+KB2qVflHClYxjQnTWLA1WXfluEHRAqX0Lu7DBNJ+vX pwhD/zBhrmIofId1qcGTkRXWzxoh6SpMyfmZJKcVLL1KqDy0NMZ03lzKlayaPu6kq0Rv FMzyYrndj5XJOFgRRqkNvNTtb595utcM+2yyCzPOPIPf2eGWN53ChA9+Qhsp8GxzwhI0 BjuCyecYx6CoMrob438jL2FDKQask3tAC9rdzBZvG9TYUX3cuvJhP7Z5LEhNSATc9gk5 qTtFABjmOjTaA26UM939iJHOXtwXUzgxcAzQeLw9ZUVtJ9SKmHeePFapd+ffPqUiHLIS FM+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QPekpFMx1ppUdRUpn5y8rEdwicf/Cm9W+uOumWzWxMs=; b=oLb6uJjxuELVKhsyz0nZzp1xg53mLsB1zvBjgrIFhC1F6o2BNogDtiP1oxmkCAHWnK K+EJQapUnbWpysiqDPgwkoZypJr0r+F23rLhsXEo8IDgo4EelZaOYe7/WxW3CBYg6c8w t4mY2l3fyuMGzCd3XCFl+5Bqp0VtPo/+BoS2YJn4ps5oVFz06ISel3/pSPGPfilHHLe2 YKyfp2pVBiFKbGwN+PSu/4JVUZElM5OyUDiC2+7JBfjlcEQY/WWWQmUADjQfEWFMfUFX rjLs6Z+vR7MFRAOiguEjc5AJpG4kDNE3kdCdxr2WD+V/YqconRRXwEEmYLVaYXJFMm7L gvDA== X-Gm-Message-State: AKGB3mI/JEZ4mVOLYIcb1OPFG4OonWx5tpvY8Uyt2hQm5Ydsgfj3cpC3 hYT7R0AkPJqoF04j1pdafYAg6k2ljKw= X-Google-Smtp-Source: ACJfBovctruowhzRjQ8ISFQRjdhYr2IorHXaf+J+zZjQ7DmVoIRpbi+TY4mzDz1SSJZw1syMtk+52Q== X-Received: by 10.159.246.19 with SMTP id b19mr8294228pls.164.1515442901747; Mon, 08 Jan 2018 12:21:41 -0800 (PST) Received: from midnight.lan (2600-6c52-6200-383d-a0f8-4aea-fac9-9f39.dhcp6.chtrptr.net. [2600:6c52:6200:383d:a0f8:4aea:fac9:9f39]) by smtp.gmail.com with ESMTPSA id o70sm28540227pfk.79.2018.01.08.12.21.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 12:21:41 -0800 (PST) From: Michael Lyle To: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org Cc: axboe@fb.com, Tang Junhui , Michael Lyle Subject: [416 PATCH 02/13] bcache: stop writeback thread after detaching Date: Mon, 8 Jan 2018 12:21:19 -0800 Message-Id: <20180108202130.31303-3-mlyle@lyle.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180108202130.31303-1-mlyle@lyle.org> References: <20180108202130.31303-1-mlyle@lyle.org> 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 the following 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 below 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. [edit by mlyle: commit log spelling/formatting] Signed-off-by: Tang Junhui Reviewed-by: Michael Lyle Signed-off-by: Michael Lyle --- drivers/md/bcache/super.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 8399fe0651f2..553e841e897d 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -906,6 +906,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);