Received: by 10.213.65.68 with SMTP id h4csp2118987imn; Sun, 8 Apr 2018 20:10:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ehEi/jZChERm0XVYg6XGjJI2Kgu69r2pRTTyPhdIQ8CSnqIcQw6C1DWCyaX37JdrAWqM1 X-Received: by 10.99.60.6 with SMTP id j6mr23260030pga.73.1523243429275; Sun, 08 Apr 2018 20:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243429; cv=none; d=google.com; s=arc-20160816; b=OaqzirPv/cnsy8/A4nmwClFDjdzFf+Ht1zk9ltWchdoDjjAJi8QCltMPPokxnjJLK+ Ks+QeZto0qgUJUFX9kAiFDCthPAZbAi0pwwZmo3qD4wJiC1LFKHKZtxiP0MfN3EL8gDs O+dQTjdVxBV8SQHVnhYXDFiygok2BRdt3MD6RQh4jlXlP3qZjSk091EEYlUHY7LBn49l 5Itd3kucR0ufIVLjoaenRssTomgMbDXW9oYN785Uem/GDB43jYZ+CKvJeLY/K9Mfq8yD BXou6s5NFSdDkO/V1ZYru5jk2G+QuUmU/FMZENqI81aMaPA2d9IuYDg7DXBqOQwwqnOg y+OQ== 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=LUiADdZjpttcxBq/CKb7N2osAK7nkiuSmzEfjfffaNo=; b=gVX9SRro4g4gdLl1GQ4cmQEYisJuNqAdvZZ8uLVLuScZyGtCC/SmcoD5nIvUaRT9nV dzEOyr8sf7/ylhwq4AUWVP5giYzU1kYoErvBCyhHD2UBoPPU+MNBjbLFiSZYuSq8kAtW tCdYaKc8Kt1Ij+dU6s5S2d0MCxj0dRHZtjZsSJ+Vls7S+t53CbeajXqjfZOnFuRHnVWC debAdHQDc929AEmI7gKsT27tdniPQv8CDMhx1uPhchNAT9OJGR2JM/IhN4x9NeXNlV+z YCd9NATO+YtGyM/vq/y01RSL0nnbY+05P61CdRedYANLO9VD5GlQ7CUYewP5On4zjuXh LHJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=jDM6khIX; 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 k8si11688557pfi.243.2018.04.08.20.09.52; Sun, 08 Apr 2018 20:10:29 -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=jDM6khIX; 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 S932980AbeDIBn3 (ORCPT + 99 others); Sun, 8 Apr 2018 21:43:29 -0400 Received: from mail-by2nam01on0123.outbound.protection.outlook.com ([104.47.34.123]:51296 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932510AbeDIAeq (ORCPT ); Sun, 8 Apr 2018 20:34:46 -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=LUiADdZjpttcxBq/CKb7N2osAK7nkiuSmzEfjfffaNo=; b=jDM6khIX8UpmuijTAgjVt3wb+B9KOZlDn8mAAtuCzk78Zm3xezoilLyiPnqCTkUTL6s5jMdgFxbxjpbII6mgJXPQL2n7lJjm7bGUAlYBnVoYEinyI+MMB/xdoqQhHUOM3w+rXPoFQPE0YoMUzu/3AOhsbexevk5+qc653V+0ItY= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0806.namprd21.prod.outlook.com (10.167.107.156) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.3; Mon, 9 Apr 2018 00:34: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:34: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.9 283/293] bcache: fix for data collapse after re-attaching an attached device Thread-Topic: [PATCH AUTOSEL for 4.9 283/293] bcache: fix for data collapse after re-attaching an attached device Thread-Index: AQHTz5lrKOVgv9J8IE6EaNrdyzEdGw== Date: Mon, 9 Apr 2018 00:26:37 +0000 Message-ID: <20180409002239.163177-283-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-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;DM5PR2101MB0806;7:AZ/wl86DGn5+BUbhZCJWgGC5LyEblf1xySTZn/93KubQ76VkqOT45tP0AcrMD+LvzkPe9VBr2fX4kTGJ4g192m5lsoOtpDlnqx7ZZqCtDSUfVbwjAr+/fe7unrq0iQ90oT+WSqTnoiGACjoWWbXI9wehJK2c2x8RYB983SHc2j8ftU9akQJMRZlTeSIwOLHV0ir5ztS/vRDyDeyWUqS+xIG5QY8XrccnEUm0g7ca1S45GnmzLiKaw417LtgwL2BI;20:3XyVn9wDmIueRTSPFEFzErTCnjvkFvDqU/m61Y3NA48cqXaJ9tVDNQN5h135qb/g/KhymSPsRQa0DwBIDuIQ95O402HiA1kcRrdufxDTDRfdj2ZIH1pR5zZbpipO40AaaY1j0mjIXKiTpMdo1hYZpF7ZN32ID6P7xup/XOzOc5I= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: bcaa6005-e470-4d70-5c4e-08d59db1afe6 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0806; x-ms-traffictypediagnostic: DM5PR2101MB0806: 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)(8121501046)(5005006)(3231221)(944501327)(52105095)(93006095)(93001095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123560045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB0806;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0806; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(376002)(396003)(366004)(39380400002)(199004)(189003)(2906002)(25786009)(2501003)(10290500003)(476003)(11346002)(446003)(97736004)(5250100002)(5890100001)(68736007)(2616005)(102836004)(6506007)(3846002)(3660700001)(486006)(3280700002)(305945005)(6666003)(99286004)(5660300001)(76176011)(1076002)(186003)(26005)(7736002)(6116002)(81156014)(81166006)(86612001)(4326008)(105586002)(10090500001)(2900100001)(54906003)(22452003)(316002)(36756003)(110136005)(107886003)(8676002)(6436002)(478600001)(53936002)(66066001)(6486002)(6512007)(575784001)(86362001)(14454004)(72206003)(8936002)(106356001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0806;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: ndL9fnou5xi7VQV640f+/MtNVD5nKdqeR8Y85241vYUQGujtqiMbeHg8tmn63B695N5Fxx+wC71Cs+G7+JzTcyiU0+2NQ9c8L9svLHZdYB1CaOlkkmK6IDcLoN1mkDptXq98eiHjIqeZFNjzEC/5BFPEYYdllSN+SZQFYI8Op8PFituXEGMbzDYh+LcSPZ/+7AvEBfgAQ0OscfMPKNwiUX1iYZ07tsE0o7sOh2L98viargHbQLwCO7ifDwBu8HXrSL3L/gIFEKuaZt/IZ0HSP25QZR854Zof+to6EdYErRxTLBVNt+Ve5RzbpgXYwwc3NIDtZDcooc+elUyIWU9MQfmZOmSaDJozCgY3iephnQYSvqHmnCBGPnR44L36M7clCwooJP/WclvY0LfkBLXFcOhPNbiomK4h8eZnE7LFIl8= 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: bcaa6005-e470-4d70-5c4e-08d59db1afe6 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:37.5509 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0806 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 02619cabda8b..7fe7df56fa33 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -904,7 +904,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 1a006f989ac2..757b13deeb1c 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -932,7 +932,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; @@ -941,7 +942,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) { @@ -1185,7 +1187,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) @@ -1708,7 +1710,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 4fbb5532f24c..1efe31615281 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -263,11 +263,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