Received: by 10.192.165.156 with SMTP id m28csp1159666imm; Wed, 11 Apr 2018 13:34:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+a+hrSqb37lmV6PFFC4ergn8x2trnpd80lGBrYC4yj4jQB2qn+2cZRvQX1sD6oOH48jI95 X-Received: by 2002:a17:902:322:: with SMTP id 31-v6mr6693387pld.122.1523478892911; Wed, 11 Apr 2018 13:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523478892; cv=none; d=google.com; s=arc-20160816; b=Snm/dRgKTg7dxU40kPhdbl5VMiOwScLh8cuI1+6cYmoXwU+akmgCImcpRlF0ZMjIYA jnFxOdAjcWZUwYByNRiPFC9bbZF1wNp0WOhq8cSR9g8a1cloDldTMXChnhYcBZl9vQmI J1eGGuSGAPDy6aNfw4fI9ix3YsPrt8/zQm4oODb5/Ep3ghxVfoaNmZ2zEBUF4MRlnKaP 84256PGRAB+5YNhLX8Su+zLzICXfJLe2ylW6Eqxc93kJAODck4qkuRgwDCho6hIK7JA1 8qo+iu9iH7YAOpLaKkaure/KImvvcF8myhPK8m8gfWwYZWxExHrDDplMtKFL3J7K+FUv Hfug== 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=j9jtOQtAjy3341dblWU2MyLDbC9eisNiLVe5EUyzga4=; b=FKmZey52uIw2b/aG/6OnwmaGieD+Uo5z64949glLwAfOgQE/f2Z4JM/wydIjT/3bRN Zcp5xAWbQYWNy1NIX3+WO3VXt5pYrQWVS4/LE77NDkeje9U8I8Ry3Yk/Kt2y7nZtgUQ5 n1iGxfwkMvpKfgYj9BYSBv0pWvN2+tSAWPwIKcZTjxRbJ/BQ68KQxPP2yJsNvE9yZ7p8 AQVehOiywEb+aj/ar5V4ez0GPP+MbdCBMxHWEa4/vZV/ax/RdrO18XxkQ5evDsZTZDFC 4vdm6B/gXrElkUziHhQIHGIZ8Guz6GCEUgYjGINtZnLqrXaj/YgM5fWPLZCKw27paJTx cetA== 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 g3si1226452pgr.635.2018.04.11.13.34.15; Wed, 11 Apr 2018 13:34:52 -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 S932613AbeDKSuS (ORCPT + 99 others); Wed, 11 Apr 2018 14:50:18 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60704 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932599AbeDKSuN (ORCPT ); Wed, 11 Apr 2018 14:50:13 -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 8FDC1D23; Wed, 11 Apr 2018 18:50:12 +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.4 149/190] bcache: stop writeback thread after detaching Date: Wed, 11 Apr 2018 20:36:35 +0200 Message-Id: <20180411183601.340539326@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183550.114495991@linuxfoundation.org> References: <20180411183550.114495991@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.4-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 @@ -890,6 +890,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);