Received: by 10.213.65.68 with SMTP id h4csp1858073imn; Mon, 19 Mar 2018 15:26:03 -0700 (PDT) X-Google-Smtp-Source: AG47ELuGVa8w57PaZRIxFYuWrzpLvClFdoMAPEdAp5WEDjCIVzkHEAKsz0nBgEiLxLBY1qlZu+dF X-Received: by 10.98.247.9 with SMTP id h9mr11578777pfi.212.1521498363133; Mon, 19 Mar 2018 15:26:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521498363; cv=none; d=google.com; s=arc-20160816; b=mDjcKCM38+zqHHdzLwT734GSoT4YdzQgnbm2xZpbYGEtRQR8rCEJVKfp54B/O3002e bXjKGWpDhtvRf3cyQbMiZlXPo50bIomT/5hCtW3jrH6KHFwL+3rSHPfheKkM4UQP2c2V AQjBhndyXT5+W/bIoG9/SUR8xzaJ8IGAOlblUmiHCiZlmCYJOGZoqXPyVnHOek++7zeq jbsAC9JCaIpmYs1Q0VrG3TnohoX9qr7ZZtQcYjGbzkTHX0VICzoMwSBAD/EdggWW2VWM Vm3HuvaXUL2ebWt/nrCrgkHi24YhDkyqPO59jf5c9CfWGnHSozpKqakBY3PdoCCDrvU+ s3lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=FrE4phwodUbXKYEqNf2kcHLAl2XxLUUUbjWl4yxEF94=; b=UAx9tkNemteGrJ4Hh0PMXeooKoEvxl9cr9mrdfUSVzRqk/q+IZ0JJw5rRBbbBaBjw/ aKsx0QzPaOg7YtWQU8HCPHO5J+rYSq3c8MKKsVy98lBhj2JIAY+ujC8+jGe8vIlIHZxa 3txVGAKdKVX7TZV3qfzrHb4lX2J3JwHAAMXrl5eBiNzdgbXRfZ8/D8u/tSc6LinQGCuG PWUKUaXTaPSY2xVJZpSZfkeBrEHvdjgbl8XJgPTlPhgexnoP1709gkIPN+hvfDD9C2mm B7CXi6JvX/1oKak1uF+qgTRUqLmoHAMcSEBUDLvRjUZQCL+jJy48mu/WT9aO9QnYN/fh ASVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=AWp4BVbQ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o5si146120pgp.16.2018.03.19.15.25.48; Mon, 19 Mar 2018 15:26:03 -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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=AWp4BVbQ; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032524AbeCSWWp (ORCPT + 99 others); Mon, 19 Mar 2018 18:22:45 -0400 Received: from mail-dm3nam03on0129.outbound.protection.outlook.com ([104.47.41.129]:48439 "EHLO NAM03-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933898AbeCSPtK (ORCPT ); Mon, 19 Mar 2018 11:49:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=FrE4phwodUbXKYEqNf2kcHLAl2XxLUUUbjWl4yxEF94=; b=AWp4BVbQAk3AE1MdbNv8RQcHuhJsgMpj0Lunvsmbzvx6C0XSk3dJRc4tkev0AMaX/lEwe/9VvWb9kqLLriWm+K6bGTyzjSVY8ys7eOBgaC37g2qvQIw/9IybOiDc2AxvAw9C62Mk9pGGO0tNwssiC8NEufooCkRFCINNZvlySC8= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0936.namprd21.prod.outlook.com (52.132.131.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.609.2; Mon, 19 Mar 2018 15:49:02 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::3d9b:79e7:94eb:5d62%5]) with mapi id 15.20.0631.004; Mon, 19 Mar 2018 15:49:01 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Tang Junhui , Michael Lyle , Jens Axboe , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 083/124] bcache: stop writeback thread after detaching Thread-Topic: [PATCH AUTOSEL for 4.15 083/124] bcache: stop writeback thread after detaching Thread-Index: AQHTv5m7sMeYrX4/U0KRwWelry1bXA== Date: Mon, 19 Mar 2018 15:48:31 +0000 Message-ID: <20180319154645.11350-83-alexander.levin@microsoft.com> References: <20180319154645.11350-1-alexander.levin@microsoft.com> In-Reply-To: <20180319154645.11350-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0936;7:iCMFqLxygl1jtrBqeKULCThZZawdeX5jvQF+XNB7QvgfIIJsCGUlkObnzppE5v7E3JVf84YoQAxMmRc6uB/IkB9XHr96/iRnyy17SXEzVGsxdKl0Ok2AMkPpWyQXi/y7awZb7Pqw4dM1n8VFOH44LGqlXo2CPismy49Fl/POcPgnkQ2qxHP4/LKbl1YCnaU1X+/eBUzh3ysyYNkf2Xj3p3bw0wv6Xq/N87YjBtl2N0vgn+sDDNyp9FSsYYoRbudB;20:TNWMHDhuaAZlgAIQCT+XBNW1J612iFAKNxipLp3mw2/jY4lJ65G2i59Kd9fBVY0aoKxbi8Ru93DXBa5zZYIQGE849baDMDibXk6VFCP0mjN64jRbJJ5qZVlTUR7fW9NONVVzkg/HI9PkZPS1x/fCcHv7woTjbSbrc0FvKMAz63A= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: feb90240-6199-4369-1b55-08d58db0efc4 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0936; x-ms-traffictypediagnostic: DM5PR2101MB0936: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(93006095)(93001095)(3231221)(944501300)(52105095)(6055026)(61426038)(61427038)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011);SRVR:DM5PR2101MB0936;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0936; x-forefront-prvs: 06167FAD59 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(979002)(39380400002)(346002)(39860400002)(366004)(376002)(396003)(199004)(189003)(2900100001)(3280700002)(2950100002)(10290500003)(66066001)(106356001)(76176011)(86612001)(6666003)(478600001)(5250100002)(6512007)(6486002)(107886003)(36756003)(97736004)(72206003)(25786009)(6436002)(53936002)(7736002)(5890100001)(2501003)(54906003)(110136005)(105586002)(10090500001)(2906002)(86362001)(305945005)(5660300001)(316002)(8676002)(6346003)(1076002)(3846002)(3660700001)(81156014)(4326008)(14454004)(26005)(6116002)(102836004)(8936002)(81166006)(6506007)(186003)(22452003)(59450400001)(99286004)(68736007)(575784001)(22906009)(217873001)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0936;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: rwtJLlElJyiEEQZwbY5RIskXcpP4DItpN3eFqjHWPHS58x1arojwIQGHmh6UUykkDFzCTaygq3TbP/tftr7HqxOqrDJEnLPgkmgKc9hBffr/lgp1pDhANv+1+MuGsJN5aF1h2q+ZFgd5EIljsa/Q8xCBeAoYENQJ6MwbzfMDY5TkiztXgHvxWcLl4uO7swxI42uVfoPpcAF8KBRBjAynczKy4g6Sit1wd259fSdoMR9NNsNASO/o2mFszC1YBjX9K111HjmQn6eeR3gFXnTfFScPC1Sysd5ctjD+F0eZuqAo26rEqx9R8WAHOx1b0ySX/jPCq5JkJeudNQxprvjNdw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: feb90240-6199-4369-1b55-08d58db0efc4 X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Mar 2018 15:48:31.3807 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0936 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 14bdaf1cef2c..47785eb22aab 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_struc= t *w) =20 mutex_lock(&bch_register_lock); =20 + cancel_delayed_work_sync(&dc->writeback_rate_update); + if (!IS_ERR_OR_NULL(dc->writeback_thread)) { + kthread_stop(dc->writeback_thread); + dc->writeback_thread =3D NULL; + } + memset(&dc->sb.set_uuid, 0, 16); SET_BDEV_STATE(&dc->sb, BDEV_STATE_NONE); =20 --=20 2.14.1