Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp803931pxb; Tue, 3 Nov 2020 13:00:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJyWJ9mf5jU8MJO6T6bKsU6AhZCl8LKfIrbazPifTPHaDfd3GGIFhjQr+Smz4Df3kCJqerLZ X-Received: by 2002:a17:906:1f85:: with SMTP id t5mr16550548ejr.352.1604437253694; Tue, 03 Nov 2020 13:00:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604437253; cv=none; d=google.com; s=arc-20160816; b=lsr34HK0KDeUMBcdhPqRhz6Xi4IdaBaS3aUtN8o2cCa9W3O9ycHnCZ3imWlNuEAMUU Bo5I8tR+MF10Aaewin5aej/vN8ydw/3T2904hC5fRe8HZlvmIEeEmQ6RSyFGYmpYxpZs VtJWk9/VC10T4fRGyMoxB4M2hgaI8QvSGErDjFCbSM3QFnMttNgkr61RQBegkjippBYo A0JSQyv3jvjOPOKV1x+nhuBCQDP/gwFt9Dz1xZxyykA9JBVgu+IHjFt6KxyQquoFEbAZ KsM8FlGIHqc5HbocBuKKnqxsA1fNypmojoViizEiablCK2jqnrpvgwEi2jWdwnIziWXx H4Mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=1R6CFp0jWVd7h3CEqPY+5Sc9Om//WndDd7B0byVc+JY=; b=Ule27+eeKHAdULBRItYe3mhY8nj6MhXvtXpRvlHLcjPmfYOYgP7oRnGU1Vf2enJuUN oQEpb2Ntd16Nao1BaMIqOofklOcVC6o31cfsqVhryYZ7zNru4pLlIQoQsI+gCtuE5ElG 3cQnGlev0qUoFTLKfKn6gTIWlifs3DuASb7U9ijllOY59liPvej4I2WOqRA+3XtOSeyD rhOjnygN7MOjU2NeWfVsMPKgxxqa1A4JAzwC83kIJuOOxz5qoleBxuNOnsSUwK3unzj0 dXGh5V7AtccO0W3hksotnKB8WdyMdidilrIjofkH8AJPTPtomQ8nb6LNmjgmuz1YD57Q 1bxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ciOkNilk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bk9si6903ejb.42.2020.11.03.13.00.30; Tue, 03 Nov 2020 13:00:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ciOkNilk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732459AbgKCU4M (ORCPT + 99 others); Tue, 3 Nov 2020 15:56:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:57612 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732454AbgKCU4K (ORCPT ); Tue, 3 Nov 2020 15:56:10 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 A19AC22409; Tue, 3 Nov 2020 20:56:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436970; bh=UVc04KZEebqJTrNn4knbVfm3fpn/+f98qwj/gWN55Cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ciOkNilkx7olZtRtg3LpAJ2B7HVtwH4oL3vi5HVWTqnslgCrM+A6eovlQqoxDogHJ jai1+ZJfv7IMVaUZgc8AhdRBaFMf1IwDxbZciwXWyBeCazjOaIBRB/OU3CKhE51qkc dQTlrvJBAitgey3iAIlq84gIhxoALCOWAWrPdzEk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anand Jain , David Sterba , Sasha Levin Subject: [PATCH 5.4 073/214] btrfs: fix replace of seed device Date: Tue, 3 Nov 2020 21:35:21 +0100 Message-Id: <20201103203257.235922029@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anand Jain [ Upstream commit c6a5d954950c5031444173ad2195efc163afcac9 ] If you replace a seed device in a sprouted fs, it appears to have successfully replaced the seed device, but if you look closely, it didn't. Here is an example. $ mkfs.btrfs /dev/sda $ btrfstune -S1 /dev/sda $ mount /dev/sda /btrfs $ btrfs device add /dev/sdb /btrfs $ umount /btrfs $ btrfs device scan --forget $ mount -o device=/dev/sda /dev/sdb /btrfs $ btrfs replace start -f /dev/sda /dev/sdc /btrfs $ echo $? 0 BTRFS info (device sdb): dev_replace from /dev/sda (devid 1) to /dev/sdc started BTRFS info (device sdb): dev_replace from /dev/sda (devid 1) to /dev/sdc finished $ btrfs fi show Label: none uuid: ab2c88b7-be81-4a7e-9849-c3666e7f9f4f Total devices 2 FS bytes used 256.00KiB devid 1 size 3.00GiB used 520.00MiB path /dev/sdc devid 2 size 3.00GiB used 896.00MiB path /dev/sdb Label: none uuid: 10bd3202-0415-43af-96a8-d5409f310a7e Total devices 1 FS bytes used 128.00KiB devid 1 size 3.00GiB used 536.00MiB path /dev/sda So as per the replace start command and kernel log replace was successful. Now let's try to clean mount. $ umount /btrfs $ btrfs device scan --forget $ mount -o device=/dev/sdc /dev/sdb /btrfs mount: /btrfs: wrong fs type, bad option, bad superblock on /dev/sdb, missing codepage or helper program, or other error. [ 636.157517] BTRFS error (device sdc): failed to read chunk tree: -2 [ 636.180177] BTRFS error (device sdc): open_ctree failed That's because per dev items it is still looking for the original seed device. $ btrfs inspect-internal dump-tree -d /dev/sdb item 0 key (DEV_ITEMS DEV_ITEM 1) itemoff 16185 itemsize 98 devid 1 total_bytes 3221225472 bytes_used 545259520 io_align 4096 io_width 4096 sector_size 4096 type 0 generation 6 start_offset 0 dev_group 0 seek_speed 0 bandwidth 0 uuid 59368f50-9af2-4b17-91da-8a783cc418d4 <--- seed uuid fsid 10bd3202-0415-43af-96a8-d5409f310a7e <--- seed fsid item 1 key (DEV_ITEMS DEV_ITEM 2) itemoff 16087 itemsize 98 devid 2 total_bytes 3221225472 bytes_used 939524096 io_align 4096 io_width 4096 sector_size 4096 type 0 generation 0 start_offset 0 dev_group 0 seek_speed 0 bandwidth 0 uuid 56a0a6bc-4630-4998-8daf-3c3030c4256a <- sprout uuid fsid ab2c88b7-be81-4a7e-9849-c3666e7f9f4f <- sprout fsid But the replaced target has the following uuid+fsid in its superblock which doesn't match with the expected uuid+fsid in its devitem. $ btrfs in dump-super /dev/sdc | egrep '^generation|dev_item.uuid|dev_item.fsid|devid' generation 20 dev_item.uuid 59368f50-9af2-4b17-91da-8a783cc418d4 dev_item.fsid ab2c88b7-be81-4a7e-9849-c3666e7f9f4f [match] dev_item.devid 1 So if you provide the original seed device the mount shall be successful. Which so long happening in the test case btrfs/163. $ btrfs device scan --forget $ mount -o device=/dev/sda /dev/sdb /btrfs Fix in this patch: If a seed is not sprouted then there is no replacement of it, because of its read-only filesystem with a read-only device. Similarly, in the case of a sprouted filesystem, the seed device is still read only. So, mark it as you can't replace a seed device, you can only add a new device and then delete the seed device. If replace is attempted then returns -EINVAL. Signed-off-by: Anand Jain Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/dev-replace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 196bd241e701a..34ddf2d75c1af 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -190,7 +190,7 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, int ret = 0; *device_out = NULL; - if (fs_info->fs_devices->seeding) { + if (srcdev->fs_devices->seeding) { btrfs_err(fs_info, "the filesystem is a seed filesystem!"); return -EINVAL; } -- 2.27.0