Received: by 10.213.65.68 with SMTP id h4csp2114785imn; Sun, 8 Apr 2018 20:05:10 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/ivKr5BChm0cKBHeN3hckLpLwD4PX4nWqv0k0Z/OO05T4QbcmaHuvAMEXE2o+Wn9SeR0Hd X-Received: by 2002:a17:902:7688:: with SMTP id m8-v6mr26476704pll.340.1523243110590; Sun, 08 Apr 2018 20:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243110; cv=none; d=google.com; s=arc-20160816; b=e1rkpTjyFHyhdsGT15B5NtNq3tiMXY0yeCMNeoakHZ2OrLYVBoLxo4AiWdo8Jg0Nyq Qa5CQk8okBgU99oEonlHAEFw2ulqObZFHOaDglAqOvfLocgJwTN+ukv1IMvrZypDnIGz K5OMzLSe5W3p59+gF8cm1m+MRwlUxrNYO65reMgmxcnpEvXi9CiWEiMIDO6gg8TUY3Xn WaXSxMAej5zJu8hm8nJpKIVYrMhHWuqKwQr3qWaSspgqntcSSML8JTcoRk+dgf3SpppP dXmBTjSRvx/Eefc4Znd3XiZ69KSGE+vHSjdwtKI111ceshsI46nm0gBUsjf3yeQmNsl1 9Yfw== 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=ZUhoN+B+2qiCROWH/mVEGi/NXIzpi+2Ses/q2ptjw9s=; b=Mel7lB7BwNBIfa2sIB29pbrcEJbdS5+qlBG0fMakhOMzp/k91uvdm0V6+yEkwYa1xX t3717WSVoJsp2iunjw8N5w3Y+jwYd3+MaWB4lR3/aZRKTTJu/+JxpD62qSftOiN8oQGe yp1ZGjBEMMzlA+An/gbcJn3D9AdhfdOZGsf2fL2TqTeXAactGrhgn6n7PnR0w2Fkqiks kf7Z8FFg1RggQrQQZbqDW+vAmLkPfZATYYaVXCPwEIBXtE+eBm9GWkeD+PG9iv/nNkib LfAxxFs9Jw7imIj+jXj3tW+QBdQBRhbA5T1ywbT7T8KBn0770lrFBNdPVD285lRQ7kLP ZANg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=dWNCZI5H; 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 g3-v6si12905614plp.471.2018.04.08.20.04.33; Sun, 08 Apr 2018 20:05: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=dWNCZI5H; 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 S1756323AbeDIAjm (ORCPT + 99 others); Sun, 8 Apr 2018 20:39:42 -0400 Received: from mail-co1nam03on0104.outbound.protection.outlook.com ([104.47.40.104]:37663 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933107AbeDIAjZ (ORCPT ); Sun, 8 Apr 2018 20:39:25 -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=ZUhoN+B+2qiCROWH/mVEGi/NXIzpi+2Ses/q2ptjw9s=; b=dWNCZI5H8uIfbYp3yxWfPi8IYtd+C1j/RUlgg1H514DnVOT+t+PDy6Vu2prxKAf7RP66LkcSQcpLMGc6wU83mmMk/J8Yw1mx3B0YLNwhuwY5Ks8rskE4rYm89S3Apuy76HuCs9MUacwvJlsODigFM35LFNhX4XLqmrIelfhATCc= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1125.namprd21.prod.outlook.com (52.132.130.150) 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:39:21 +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:39:21 +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.4 157/162] bcache: fix for data collapse after re-attaching an attached device Thread-Topic: [PATCH AUTOSEL for 4.4 157/162] bcache: fix for data collapse after re-attaching an attached device Thread-Index: AQHTz5ng3sImlIyOSEaVlxJD+YHr3w== Date: Mon, 9 Apr 2018 00:29:53 +0000 Message-ID: <20180409002738.163941-157-alexander.levin@microsoft.com> References: <20180409002738.163941-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002738.163941-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;DM5PR2101MB1125;7:FfdmwZUbhY/WruNubNfRqoX8MY1x+ZiQYm0ydTp8e//dWevEcNNbRjVt35Uy0jJR0heHKwJ4X0jI6jtj76UC2+sZS6t3eNIZQJtO90lhBoJf8MpV2H3v/OJzULZNtB59GClRc4C5I1pdkY54gjge3uxLqzlyvsiSYOVdz7gYzJ9jbVLfOcV0Lq3UChmRFWY93NnN6nk1xRoS175iEiXmpiplBdeouokEQaD21kI62SJSIW/Isq7q/77ul9H3eCDT;20:8wNIsUtuuiA/NS3lv43etVUy8ZTbsmem7B56yDmFKPoXTcaTcWKRVQBKbD6bYlUTczP+LUzTXixMXYU9bNXjagxCw5HZu9Wbs+XJsk6V7WOnSSghbDr936EhR9Ojf4lUVSGkHMzc8o/MQyTMMiAA8V8I/X6MP2PicQM8vFgMNLs= X-MS-Office365-Filtering-Correlation-Id: 010b0e32-d19f-4bb4-5bbd-08d59db255e0 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB1125; x-ms-traffictypediagnostic: DM5PR2101MB1125: 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)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1125;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1125; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(346002)(39860400002)(39380400002)(366004)(376002)(396003)(189003)(199004)(2906002)(25786009)(6512007)(10090500001)(3280700002)(10290500003)(6666003)(3660700001)(316002)(110136005)(54906003)(11346002)(107886003)(2616005)(476003)(446003)(36756003)(99286004)(86612001)(53936002)(4326008)(486006)(6436002)(3846002)(81156014)(305945005)(5250100002)(1076002)(102836004)(14454004)(66066001)(5890100001)(7736002)(105586002)(81166006)(106356001)(8676002)(97736004)(6116002)(6506007)(6486002)(5660300001)(186003)(76176011)(22452003)(72206003)(478600001)(2501003)(2900100001)(26005)(86362001)(575784001)(8936002)(68736007)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1125;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: VIp+27e2zGMEgmfEEtw+cW3X9tLActuDTGcV9VmhppJhsbC/zbUe5RWsCCKBZyN5ndgoTXC2J6Y9KSHkz8GjaE7zRQFllYu8xApmexZXkJ1LvI3IqQ9dLcH9TwVIOtUL1bV1fDSyPWHSK334Eiyx8i+LjvHDg4fQJolb/4Jf5qwLVQIDgb3VB9g3g7hsXFxTvKUg4NLMjoleb4I1aS31MbnOCfdsYx33js9QP6wGjDaBOO/3ruhCWmMX8s+IVvNxdtbsbtW+/O0bio3uB7gv1vpoQDaEHbukJGB8EvSn1VQH1FWSrxj0Q5WBdwdIXZGtJeFLsMVwEHXZJ+8QtpydrW07A+oBn+5/by4Hr5/WZKFKrVRuANSZ0cqW1ni/miq8OwbH96tKlWZZClbaE1oabyottA3yQkyyrd4cYIWyBQU= 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: 010b0e32-d19f-4bb4-5bbd-08d59db255e0 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:29:53.1934 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1125 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 132d6417c66e..4a3ae14d25e0 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -930,7 +930,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; @@ -939,7 +940,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) { @@ -1183,7 +1185,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) @@ -1705,7 +1707,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