Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2473551imm; Mon, 28 May 2018 08:45:30 -0700 (PDT) X-Google-Smtp-Source: AB8JxZocUVrg1gcH9iyCydG/w6Pw9j3m0KHbECVttIUKCQDIp/q3GqvppAd3Sae1fgofOeZ8ISBs X-Received: by 2002:a62:449c:: with SMTP id m28-v6mr13936397pfi.145.1527522330327; Mon, 28 May 2018 08:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527522330; cv=none; d=google.com; s=arc-20160816; b=hy0aU0IPuFgplbOgVre8QC8jgtcuCAT3dkGzHt+0FfJJZE0iNZPlUZ8v35ZZSGtsIN LfoPdSYrO7CkHZ0fXOE8x5s5ouepm1YYwtZJCNmJ9q0IWT/q9Jh4Du368hHqPG7qVU6k VvBMfO2pmvJmdDppKCdRP/m6oBwIeG+u7+WF8S0EqYUPGV21otnbPnkKIbRRVn5sxKCd 9uFrxzwFvRUEC2n2/ULaa0tu08PFb8v6P2eTVwxNfozYU6kSQ10wvzkrKdhZV2YjjIbc xPJHQ4WTNMMyER7oqpvpvC4wjwnhyBxrpQJQyXK1vczRmu1L7M2YJfXp0L8KrIokmU0j yqNw== 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:dkim-signature :arc-authentication-results; bh=p7WrCPHBP3fRBPM4Zgld3U9CySypsXNF184x6Ud5fgs=; b=Hv/bITGB6DOIyvsrdvKLM+NaNEihxdXp4u/qXCQtY+Q0+xB5RPRHuOwEXft7MZLVev DqIJyE3Li2QLrWPlihsHHKCZHPE1UyhTACmHdJxQH8fcCzag1ek2PcJxfaYEM2lifVZd Q9bjk1kRmK+O1qh7NMMKBxxDn6xw7eYoXFqaigxl1Ya2hCHjSp6c2rQcVZxGsotvlFb0 8gpyls8jEDbqvdisDmT7zeWqYmq+bU6u8YZ5xDVDM2hr4bjEsQVYPnpfkEExUZDQdvpX 9tECwQQccylNGW980k8hwMxAYuti/OoT4dWF5yN6xmxjzWxdSqOi0yN0EWXePlZrzca6 GvZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B7RTmnTW; 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 l22-v6si6066637pgu.353.2018.05.28.08.45.15; Mon, 28 May 2018 08:45:30 -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=@kernel.org header.s=default header.b=B7RTmnTW; 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 S968633AbeE1KRG (ORCPT + 99 others); Mon, 28 May 2018 06:17:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:37142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966814AbeE1KRA (ORCPT ); Mon, 28 May 2018 06:17:00 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8F8B32089E; Mon, 28 May 2018 10:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527502620; bh=XdzjRXK1vFMc7SOlp4y3uispV7AAX+6TkKkx3QW/q+I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B7RTmnTWYgQ8sB063xcr7i/LvvNWW2BUCROfWw1p2wO9W8dkCWcV5S0TqC4DFkJIk jnhFjTy5THem5WDec1X0O/tX/V//j6fNwaWXfWMj1cEkvmpMYD/KNImLkg6Xqe+v3+ yscgetEPmUNtzaLgfebhU+aYV74t1/Lt8SmW4mhs= 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.4 067/268] bcache: fix for data collapse after re-attaching an attached device Date: Mon, 28 May 2018 12:00:41 +0200 Message-Id: <20180528100209.453131120@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100202.045206534@linuxfoundation.org> References: <20180528100202.045206534@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.4-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- 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(-) --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -904,7 +904,7 @@ void bcache_write_super(struct cache_set int bch_flash_dev_create(struct cache_set *c, uint64_t size); -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 *); --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -936,7 +936,8 @@ void bch_cached_dev_detach(struct cached cached_dev_put(dc); } -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 = cpu_to_le32(get_seconds()); struct uuid_entry *u; @@ -945,7 +946,8 @@ int bch_cached_dev_attach(struct cached_ bdevname(dc->bdev, buf); - 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; if (dc->disk.c) { @@ -1189,7 +1191,7 @@ static void register_bdev(struct cache_s 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); if (BDEV_STATE(&dc->sb) == BDEV_STATE_NONE || BDEV_STATE(&dc->sb) == BDEV_STATE_STALE) @@ -1711,7 +1713,7 @@ static void run_cache_set(struct cache_s bcache_write_super(c); list_for_each_entry_safe(dc, t, &uncached_devices, list) - bch_cached_dev_attach(dc, c); + bch_cached_dev_attach(dc, c, NULL); flash_devs_run(c); --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -263,11 +263,13 @@ STORE(__cached_dev) } if (attr == &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; list_for_each_entry(c, &bch_cache_sets, list) { - v = bch_cached_dev_attach(dc, c); + v = bch_cached_dev_attach(dc, c, set_uuid); if (!v) return size; }