Received: by 10.213.65.68 with SMTP id h4csp2122947imn; Sun, 8 Apr 2018 20:16:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/8td/TGYkWCMiIBWe5cEyxv7KfZDvUJ+F6yTLJYvp6XQxtbaewTW+wQBAhgWqgA2qczSkp X-Received: by 2002:a17:902:ab81:: with SMTP id f1-v6mr36219540plr.5.1523243770267; Sun, 08 Apr 2018 20:16:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243770; cv=none; d=google.com; s=arc-20160816; b=c+g8oomdSUo3h4v87YL4K+ECM5pYOSXIjMpbsoNb9JjytdujkswSfQPSQU75GnyHiz Y6ve/Bbu+dajHvGJtXcxEZ0QLvObqmscRk5HHbM9bIH7Hi2g+CJfO+xKyQCwVIRuMog0 VkPUVogPHyHRGVPWGgxc+SBAm/OGz1WSiM+fyWSrOSMXd+TKgpaRA2v+3gZ3l6CXuZN+ iWmbtzeQaP+7CjowwkhQopwIw+31hd1rj4Zkww1i7IIteHpWVpwY+Cs1RE33+vof9xbI CQDKbVC2IiL7DTUzoDZ3Axy+l1VUdJ5SDwn8VlRoEv5d2A/7jbQ172Yb9M6WN31yEJ5d 9t8w== 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=lA31hX01/+k3hSjlzBAN4XDdpkZJPQbi8Vgno/hGA78=; b=qUuOCOrneBGIvqS8uxPpVyJTfw0SfUppaM5Qdqa2NE6CAe8xpmrz87tv5e1XnpmfiR 0GehBTei4AkMXTUQWxJjdS4acnKBauk1I7Kj7uNhsDYDg2ITHdOITao5KJ8GssZQxIAf /8CV3h86RoPHlQElVJ8Pw+gDTRCYSP3voxcKj8FICgWrCwxq2Lzxl0cl8hj7eeQ6MCWn jSv3UxsZ3GQLiXEBNZBDdG0/viauWSTfsG2SwmM8rlc1aRfkV31IFEu2h97R+/Gk9C0D ulJ5PnYAjPz0JLLFgsVxTGqLDiVitzClQFnuGL5cDjOiJqyidhL8wtBNZRToqBSkIPpK FiTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=oA7IVDLd; 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 h61-v6si6195049pld.152.2018.04.08.20.15.33; Sun, 08 Apr 2018 20:16:10 -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=oA7IVDLd; 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 S1756035AbeDIC4j (ORCPT + 99 others); Sun, 8 Apr 2018 22:56:39 -0400 Received: from mail-sn1nam02on0125.outbound.protection.outlook.com ([104.47.36.125]:42928 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755235AbeDIAZp (ORCPT ); Sun, 8 Apr 2018 20:25:45 -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=lA31hX01/+k3hSjlzBAN4XDdpkZJPQbi8Vgno/hGA78=; b=oA7IVDLdckNJq0euwWM60/KhseQFfNFas141/gnKMdUYtfus/D4GmN8rSJT4PUvoZzyRrOf7XSmLLb9sG5yQU6N+QGexi3C5X1RIvjpZUI5y7ippfGqhSX13f+Zws+OL7BZYXyJFy08cId5GDtvGyBnq7vz7mUPdKs6g966u0wA= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0725.namprd21.prod.outlook.com (10.167.107.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:25:42 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:25:42 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Tang Junhui , Jens Axboe , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 138/161] bcache: fix for data collapse after re-attaching an attached device Thread-Topic: [PATCH AUTOSEL for 4.14 138/161] bcache: fix for data collapse after re-attaching an attached device Thread-Index: AQHTz5i+vCAwe+zmtEuKKP4sQZ3JAQ== Date: Mon, 9 Apr 2018 00:21:46 +0000 Message-ID: <20180409001936.162706-138-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-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;DM5PR2101MB0725;7:tdc62DnRuhYhsUiFYMW0hBeom/L+HaSvajOY8bd34P8IKWXTjrQym/p6oL4ZkXsqBUm7TSMVW3RKjNHjOVBF2N7McEejh1v2AvThxDS/TRJeJ3+l7OirCdoqqxfSh0+sjwNi9ORnbkZB6loTjjGkgHXZqWXVQOUbIdESFWB9fRjd4oyBpyV4hL0nY/HM4CTzxXjfHbMCvM0NtTHMo26zS7EhbcZ95u/Adi1QEKkb8whXOm2VD6DT4KqqiYC62pSE;20:AeH4bOUn1DeWLuqzVYKdzTNXPuWZdVlmstlxuGjkcVfT3E/qT7wgHcqFY7KoNhdm3jiiLupUb1PJGA2y8UEb/gFrCUiNB1itq7CK8P4VHiUB0bJbIqu7MeRmNzWJBYIgakJ6KdJDiqIX2npNemua98axrlM6ZJZA7MEblhU9pv0= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 0c8798be-feba-46f2-f7d0-08d59db06ded x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0725; x-ms-traffictypediagnostic: DM5PR2101MB0725: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; 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)(3231221)(944501327)(52105095)(93006095)(93001095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0725;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0725; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(346002)(366004)(376002)(396003)(39860400002)(199004)(189003)(6486002)(81166006)(26005)(6512007)(4326008)(6436002)(81156014)(8676002)(97736004)(186003)(36756003)(72206003)(53936002)(107886003)(2906002)(86362001)(76176011)(110136005)(305945005)(10090500001)(486006)(3660700001)(102836004)(5660300001)(14454004)(476003)(575784001)(86612001)(446003)(99286004)(68736007)(66066001)(11346002)(54906003)(2616005)(1076002)(7736002)(5250100002)(25786009)(8936002)(478600001)(2900100001)(2501003)(3280700002)(105586002)(316002)(106356001)(22452003)(6506007)(3846002)(10290500003)(5890100001)(6116002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0725;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: ILIDoC0Ysb9UjDJfYgJmELITl6yLkP63JxEpyHUWfyE5JAWLdv+qZFeh82tIa4Yoo/9JS7XZUOa1nEfqQp/Dn+gRbuK3iTnYVaU/3TqIihDuH+HUA4IzC+/WgdJbJvv0TtL1No3tmZn2FT1yYXDic7VjvqDbqwJ4WTk9zJRRjzZJUYltFqflBcXMM88yBYWRfUaycLPmUKykiTwmOKWQ21UL8E3tVcj0qgnJyaCc/lWhNpLgArem22fzbXUvtVitasfFGmaAP6icrwaGReMCCHdQlEcaHreyEPublirBhZidUZyi5x4aWgliS3sVAIJXVnvrGCNFf7eT5APu0I0fzXMQki5nNbxb8dDOOHsxUTm7+/ExWE+QhjrckWgNu/iCO5otYiWsC+glvoplqcETE4M4slWaX5GghkjFbaJH2io= 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: 0c8798be-feba-46f2-f7d0-08d59db06ded X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:21:46.1905 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0725 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tang Junhui [ Upstream commit 73ac105be390c1de42a2f21643c9778a5e002930 ] back-end device sdm has already attached a cache_set with ID f67ebe1f-f8bc-4d73-bfe5-9dc88607f119, then try to attach with another cache set, and it returns with an error: [root]# cd /sys/block/sdm/bcache [root]# echo 5ccd0a63-148e-48b8-afa2-aca9cbd6279f > attach -bash: echo: write error: Invalid argument After that, execute a command to modify the label of bcache device: [root]# echo data_disk1 > label Then we reboot the system, when the system power on, the back-end device can not attach to cache_set, a messages show in the log: Feb 5 12:05:52 ceph152 kernel: [922385.508498] bcache: bch_cached_dev_attach() couldn't find uuid for sdm in set In sysfs_attach(), dc->sb.set_uuid was assigned to the value which input through sysfs, no matter whether it is success or not in bch_cached_dev_attach(). For example, If the back-end device has already attached to an cache set, bch_cached_dev_attach() would fail, but dc->sb.set_uuid was changed. Then modify the label of bcache device, it will call bch_write_bdev_super(), which would write the dc->sb.set_uuid to the super block, so we record a wrong cache set ID in the super block, after the system reboot, the cache set couldn't find the uuid of the back-end device, so the bcache device couldn't exist and use any more. In this patch, we don't assigned cache set ID to dc->sb.set_uuid in sysfs_attach() directly, but input it into bch_cached_dev_attach(), and assigned dc->sb.set_uuid to the cache set ID after the back-end device attached to the cache set successful. Signed-off-by: Tang Junhui Reviewed-by: Michael Lyle Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/bcache/bcache.h | 2 +- drivers/md/bcache/super.c | 10 ++++++---- drivers/md/bcache/sysfs.c | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index abd31e847f96..e4a3f692057b 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -906,7 +906,7 @@ void bcache_write_super(struct cache_set *); =20 int bch_flash_dev_create(struct cache_set *c, uint64_t size); =20 -int bch_cached_dev_attach(struct cached_dev *, struct cache_set *); +int bch_cached_dev_attach(struct cached_dev *, struct cache_set *, uint8_t= *); void bch_cached_dev_detach(struct cached_dev *); void bch_cached_dev_run(struct cached_dev *); void bcache_device_stop(struct bcache_device *); diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index c8cbb6cc1405..31cf9227da72 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -933,7 +933,8 @@ void bch_cached_dev_detach(struct cached_dev *dc) cached_dev_put(dc); } =20 -int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c) +int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c, + uint8_t *set_uuid) { uint32_t rtime =3D cpu_to_le32(get_seconds()); struct uuid_entry *u; @@ -942,7 +943,8 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct= cache_set *c) =20 bdevname(dc->bdev, buf); =20 - if (memcmp(dc->sb.set_uuid, c->sb.set_uuid, 16)) + if ((set_uuid && memcmp(set_uuid, c->sb.set_uuid, 16)) || + (!set_uuid && memcmp(dc->sb.set_uuid, c->sb.set_uuid, 16))) return -ENOENT; =20 if (dc->disk.c) { @@ -1184,7 +1186,7 @@ static void register_bdev(struct cache_sb *sb, struct= page *sb_page, =20 list_add(&dc->list, &uncached_devices); list_for_each_entry(c, &bch_cache_sets, list) - bch_cached_dev_attach(dc, c); + bch_cached_dev_attach(dc, c, NULL); =20 if (BDEV_STATE(&dc->sb) =3D=3D BDEV_STATE_NONE || BDEV_STATE(&dc->sb) =3D=3D BDEV_STATE_STALE) @@ -1706,7 +1708,7 @@ static void run_cache_set(struct cache_set *c) bcache_write_super(c); =20 list_for_each_entry_safe(dc, t, &uncached_devices, list) - bch_cached_dev_attach(dc, c); + bch_cached_dev_attach(dc, c, NULL); =20 flash_devs_run(c); =20 diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 234b2f5b286d..6dd03cf9053b 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -265,11 +265,13 @@ STORE(__cached_dev) } =20 if (attr =3D=3D &sysfs_attach) { - if (bch_parse_uuid(buf, dc->sb.set_uuid) < 16) + uint8_t set_uuid[16]; + + if (bch_parse_uuid(buf, set_uuid) < 16) return -EINVAL; =20 list_for_each_entry(c, &bch_cache_sets, list) { - v =3D bch_cached_dev_attach(dc, c); + v =3D bch_cached_dev_attach(dc, c, set_uuid); if (!v) return size; } --=20 2.15.1