From patchwork Thu Mar 1 16:05:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Lyle X-Patchwork-Id: 10251833 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3BF19602B5 for ; Thu, 1 Mar 2018 16:06:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CE4B285F3 for ; Thu, 1 Mar 2018 16:06:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 202862865F; Thu, 1 Mar 2018 16:06:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 678ED28609 for ; Thu, 1 Mar 2018 16:06:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1032838AbeCAQGC (ORCPT ); Thu, 1 Mar 2018 11:06:02 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:43484 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032539AbeCAQF7 (ORCPT ); Thu, 1 Mar 2018 11:05:59 -0500 Received: by mail-pg0-f68.google.com with SMTP id e9so2471265pgs.10 for ; Thu, 01 Mar 2018 08:05:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lyle-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=eF/tgVWqn8DGvOrDVJayhqzAIyvBLrqOLIpZgPp0LSY=; b=f2CdjUmMMRSEr0BnS1o+raHDF+UEigWSohY4eMU337CSAZ7S5JbsJTtnBVBwgjzhVH sXaYmfzrf0wAHow29UTjZzZhyYnmJYetMzRvvgBB5YwG11oQFAFopGbE3PSluzWrl/kI EwJSlKYkwzWApzEE1S0VYqYZwJVk03uCtireJDMJzGTsGqCXcK+Tw/1l1tOOUnSXEIyw 42mb1I+eyR4W48A2gb6ngRx/+oy/hWKJnQA5fWY8+I2FWEl4YJMIppKbBQsmxVqwkRNh nfHIoHGrw3qRx4QtBr95v2lpa5SgOnN0FZ03KOtdX4okX4L0tZTPI1p7OI8M9W/k7AyN VwsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=eF/tgVWqn8DGvOrDVJayhqzAIyvBLrqOLIpZgPp0LSY=; b=fNNS31KOWYze/XJC2/WZRu/osXKOvQFHWm6nyGjnNePKrZbAOKX13QYz8ejoG7t48/ ZpL8UInJen/cqTqlpKfBV4Otl/kKDm8QINjUmBu+V4dqlafBrZuQI+Dwn7d1dSetFZLK H8wHZ8N7za6wGOy4oZ6KSxqHO+jBk4VU8CZynPnZzA8T2+W9bnUq77EoEFID8qbhz5Ap q4gHfQk6t7KMsvJOk1wVr211DdVZxS1S4a7gnxN9Fsml60gsffwbvPJDoeIDJwNvO0PA /r7h30isjBVWrNwQLq9x8RoFGvxqEdqCAD6zE/vBGmVlZLa5wPMWVgWVddd5b0+nDlXE vvxQ== X-Gm-Message-State: APf1xPA+mRAylDMedf64dKwZDfJluP0AvZkpdgXeLBbjsEYbzEJSOdPK ofM/cP6JVq4iMIngob4FqrK/9y5MERA= X-Google-Smtp-Source: AG47ELsFabIzhYJyLGnJwSuqkOq20SMWHOpVY4MmBc1PYSNnJzoJTjoe11QPk0UcuKmz5W2Tw64Bqg== X-Received: by 10.101.98.137 with SMTP id f9mr1912930pgv.6.1519920358893; Thu, 01 Mar 2018 08:05:58 -0800 (PST) Received: from midnight.lan (2600-6c52-6200-09b7-0000-0000-0000-0d66.dhcp6.chtrptr.net. [2600:6c52:6200:9b7::d66]) by smtp.gmail.com with ESMTPSA id 205sm8722479pfy.117.2018.03.01.08.05.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Mar 2018 08:05:58 -0800 (PST) From: Michael Lyle Cc: linux-bcache@vger.kernel.org, linux-block@vger.kernel.org, Michael Lyle Subject: [PATCH] bcache: don't attach backing with duplicate UUID Date: Thu, 1 Mar 2018 08:05:46 -0800 Message-Id: <20180301160546.12334-1-mlyle@lyle.org> X-Mailer: git-send-email 2.14.1 To: unlisted-recipients:; (no To-header on input) Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This can happen e.g. during disk cloning. This is an incomplete fix: it does not catch duplicate UUIDs earlier when things are still unattached. It does not unregister the device. Further changes to cope better with this are planned but conflict with Coly's ongoing improvements to handling device errors. In the meantime, one can manually stop the device after this has happened. Attempts to attach a duplicate device result in: [ 136.372404] loop: module loaded [ 136.424461] bcache: register_bdev() registered backing device loop0 [ 136.424464] bcache: bch_cached_dev_attach() Tried to attach loop0 but duplicate UUID already attached My test procedure is: dd if=/dev/sdb1 of=imgfile bs=1024 count=262144 losetup -f imgfile Signed-off-by: Michael Lyle --- drivers/md/bcache/super.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index 9c141a8aaacc..5cace6892958 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -963,6 +963,7 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c, uint32_t rtime = cpu_to_le32(get_seconds()); struct uuid_entry *u; char buf[BDEVNAME_SIZE]; + struct cached_dev *exist_dc, *t; bdevname(dc->bdev, buf); @@ -987,6 +988,16 @@ int bch_cached_dev_attach(struct cached_dev *dc, struct cache_set *c, return -EINVAL; } + /* Check whether already attached */ + list_for_each_entry_safe(exist_dc, t, &c->cached_devs, list) { + if (!memcmp(dc->sb.uuid, exist_dc->sb.uuid, 16)) { + pr_err("Tried to attach %s but duplicate UUID already attached", + buf); + + return -EINVAL; + } + } + u = uuid_find(c, dc->sb.uuid); if (u &&