Received: by 10.192.165.156 with SMTP id m28csp45175imm; Tue, 10 Apr 2018 16:03:55 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/NgBqQJETEahJoxguGqzqtmqgioszQEEy/OfxmHe1Vymei6nU5Rt+rtj+RMcDv77frGcPz X-Received: by 10.98.223.149 with SMTP id d21mr1909419pfl.160.1523401435571; Tue, 10 Apr 2018 16:03:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523401435; cv=none; d=google.com; s=arc-20160816; b=Dwf4D3RffoUKpOwyntbd/s8N/oRb25UbSGY/smTvYvOJek6TqkMoVp/Ke+6zJDPoc2 rlVlqEvFuqiTEa2uWcH7SzEzK0g710hXP4Bxk0Q7O0oghanmOnLVQnY0mrU+MENjbZyu b1j8vdYVkKcwLhazGURqOMr0sO8kuvuidBNRNfmuajiqTlTAuHcalH2/d44Tsp8evRai pHoS1Hb+Bd9e4caXnEyjtFJcHVayAXXGmWCREIFGJVcyallfgIX3Pv6rXTVxvZOSPxO9 SG40li75hYzNv2g6P+oFiKrHG9f/ugw94XTDF2LI9INAHyzHGanE2v4qkfMcDnU3mgyT 3jYg== 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=lDZpQYtmtY4FfmQ1W/V6dfXWJHHweV6B8oDkIfpXxbQ=; b=o++YQRlK/xiMiMNALu6Tvb2k6J0ew55gE4dLL5QmcSO/qlEspwWLXsZIQcRabqp8qZ 1nQ7cw26fJ7Dg0zyb0fbzR3Br12YKWWip67l1G67J3cGsNqtfrsErWxMMfCcyBjiHt3E d+SnVl5LMaNHmYgMgD9R7oLC43DOPCF1LirSNom+dxoTVJgh890815hnbJEgQstH4RHN iPv8gjEHZZHijjeWT2RdhhCM0i1r7jqiTJgJBQrwKhM3pQJA/H+psWxFpLT/uvgMP0DN TPWuw6I7kDrnVd/fZ7Z6siSKBdvVASvdTp9tA+PnFZqCoHFlULg8sUsUrucceMP2Mp1P 9YtQ== 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 f1si2388437pgq.806.2018.04.10.16.03.17; Tue, 10 Apr 2018 16:03:55 -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 S1755623AbeDJWgN (ORCPT + 99 others); Tue, 10 Apr 2018 18:36:13 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42380 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755606AbeDJWgL (ORCPT ); Tue, 10 Apr 2018 18:36:11 -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 66641DFA; Tue, 10 Apr 2018 22:36:10 +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.14 058/138] bcache: stop writeback thread after detaching Date: Wed, 11 Apr 2018 00:24:08 +0200 Message-Id: <20180410212908.834750246@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180410212902.121524696@linuxfoundation.org> References: <20180410212902.121524696@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.14-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 @@ -893,6 +893,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);