Received: by 10.192.165.156 with SMTP id m28csp68351imm; Tue, 10 Apr 2018 16:35:40 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+whKyUTvSvYrrVNuarDC+ru7qnJYlyOi8zCothGD+EwJ19ce0AlqPgrBjTZgYog+7vjbyI X-Received: by 10.98.71.211 with SMTP id p80mr1978374pfi.136.1523403340781; Tue, 10 Apr 2018 16:35:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523403340; cv=none; d=google.com; s=arc-20160816; b=sfOsrpWDQELmkOyoUI+/X8lAT3BvYpqwAB//ADxsW1QlgmKHU/7m0n8FMg75H55rom EJGnJnOOS/523CK1M/MsgGBgjbjM5lQAbFoLAb0SRTud1Zogd9MGDL5F5jkFqi5kRgWc IJRxIW2QxguXkheAmqsRF535fLqMbRObmAMo6RvWLmvH+dS1GxQuZ/EU2oKeO58TLtHk njknpfyA5puuHIRk/+xSnWnhbG+tXBH+NSI8O0ieSefh2Pt3RPDCO+ZyYQ1qISicEBPY HFZTtX2k1dDR8cCb5d7+f8tt5CGD7JnOI6yElOw7KcnEnLv/jDBAZFsTFlxhpkqOdvxD 1byw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=YHgfYIJZo73rVbQlvyfxSR8dim9NBBoMNxzYy2NIkXw=; b=wpUQbWT8IuWTLfXZU8FW6gJ+TXg1OOhA+TNIoaF0Rlo4DSBCpNFqIx6EMqEQNqoP74 hC9Fd9/YXuYcUKC/bVEQFRVITBcyp8rGXgjopbr/ZiMozVJz/vlE0hNG8Sw/ciGXZ0ZO vRPeYkyxD9dw5DCWnmg4Ert2UbfFt7qSUHeTyf088hrAJOBEPS+9yUSnOFgCnyVa3e96 yROrCFJXEiARSQbxKY1WXXOKKRvI6vJu7u5Qznrl4Ie2WGIF3R9rtyV49HjJ2V8HKHpj YoWYnDPt9v1qsgoJ23o9QotWrTAz7nSPGuPAbgik/IoAjqjnzjKFmK9IaA6U4dOc42vd mtfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s21si2951644pfi.87.2018.04.10.16.35.04; Tue, 10 Apr 2018 16:35:40 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755331AbeDJX1H (ORCPT + 99 others); Tue, 10 Apr 2018 19:27:07 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:39536 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754299AbeDJW3Z (ORCPT ); Tue, 10 Apr 2018 18:29:25 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 26637D7C; Tue, 10 Apr 2018 22:29:25 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tang Junhui , Michael Lyle , Jens Axboe , Sasha Levin Subject: [PATCH 4.15 073/168] bcache: stop writeback thread after detaching Date: Wed, 11 Apr 2018 00:23:35 +0200 Message-Id: <20180410212803.298076212@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212800.144079021@linuxfoundation.org> References: <20180410212800.144079021@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tang Junhui [ Upstream commit 8d29c4426b9f8afaccf28de414fde8a722b35fdf ] 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 Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/md/bcache/super.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -906,6 +906,12 @@ static void cached_dev_detach_finish(str 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);