linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Anand Jain <anand.jain@oracle.com>,
	David Sterba <dsterba@suse.com>, Sasha Levin <sashal@kernel.org>,
	linux-btrfs@vger.kernel.org
Subject: [PATCH AUTOSEL 5.4 56/80] btrfs: fix replace of seed device
Date: Mon, 26 Oct 2020 19:54:52 -0400	[thread overview]
Message-ID: <20201026235516.1025100-56-sashal@kernel.org> (raw)
In-Reply-To: <20201026235516.1025100-1-sashal@kernel.org>

From: Anand Jain <anand.jain@oracle.com>

[ 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 <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 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.25.1


  parent reply	other threads:[~2020-10-27  0:01 UTC|newest]

Thread overview: 81+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-26 23:53 [PATCH AUTOSEL 5.4 01/80] powerpc/powernv/smp: Fix spurious DBG() warning Sasha Levin
2020-10-26 23:53 ` [PATCH AUTOSEL 5.4 02/80] mm: fix exec activate_mm vs TLB shootdown and lazy tlb switching race Sasha Levin
2020-10-26 23:53 ` [PATCH AUTOSEL 5.4 03/80] powerpc: select ARCH_WANT_IRQS_OFF_ACTIVATE_MM Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 04/80] sparc64: remove mm_cpumask clearing to fix kthread_use_mm race Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 05/80] f2fs: add trace exit in exception path Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 06/80] f2fs: fix uninit-value in f2fs_lookup Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 07/80] f2fs: fix to check segment boundary during SIT page readahead Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 08/80] s390/startup: avoid save_area_sync overflow Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 09/80] um: change sigio_spinlock to a mutex Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 10/80] f2fs: handle errors of f2fs_get_meta_page_nofail Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 11/80] MIPS: ftrace: Remove redundant #ifdef CONFIG_DYNAMIC_FTRACE Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 12/80] ARM: 8997/2: hw_breakpoint: Handle inexact watchpoint addresses Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 13/80] NFS4: Fix oops when copy_file_range is attempted with NFS4.0 source Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 14/80] power: supply: bq27xxx: report "not charging" on all types Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 15/80] xfs: fix realtime bitmap/summary file truncation when growing rt volume Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 16/80] video: fbdev: pvr2fb: initialize variables Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 17/80] ath10k: start recovery process when payload length exceeds max htc length for sdio Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 18/80] ath10k: fix VHT NSS calculation when STBC is enabled Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 19/80] drm/brige/megachips: Add checking if ge_b850v3_lvds_init() is working correctly Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 20/80] selftests/x86/fsgsbase: Reap a forgotten child Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 21/80] media: videodev2.h: RGB BT2020 and HSV are always full range Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 22/80] media: platform: Improve queue set up flow for bug fixing Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 23/80] usb: typec: tcpm: During PR_SWAP, source caps should be sent only after tSwapSourceStart Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 24/80] media: tw5864: check status of tw5864_frameinterval_get Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 25/80] media: imx274: fix frame interval handling Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 26/80] mmc: via-sdmmc: Fix data race bug Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 27/80] drm/bridge/synopsys: dsi: add support for non-continuous HS clock Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 28/80] arm64: topology: Stop using MPIDR for topology information Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 29/80] printk: reduce LOG_BUF_SHIFT range for H8300 Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 30/80] ia64: kprobes: Use generic kretprobe trampoline handler Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 31/80] kgdb: Make "kgdbcon" work properly with "kgdb_earlycon" Sasha Levin
2020-10-27 12:01   ` Daniel Thompson
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 32/80] bpf: Permit map_ptr arithmetic with opcode add and offset 0 Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 33/80] media: uvcvideo: Fix dereference of out-of-bound list iterator Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 34/80] selftests/bpf: Define string const as global for test_sysctl_prog.c Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 35/80] samples/bpf: Fix possible deadlock in xdpsock Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 36/80] riscv: Define AT_VECTOR_SIZE_ARCH for ARCH_DLINFO Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 37/80] cpufreq: sti-cpufreq: add stih418 support Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 38/80] USB: adutux: fix debugging Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 39/80] uio: free uio id after uio file node is freed Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 40/80] coresight: Make sysfs functional on topologies with per core sink Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 41/80] usb: xhci: omit duplicate actions when suspending a runtime suspended host Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 42/80] SUNRPC: Mitigate cond_resched() in xprt_transmit() Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 43/80] arm64/mm: return cpu_all_mask when node is NUMA_NO_NODE Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 44/80] can: flexcan: disable clocks during stop mode Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 45/80] xfs: don't free rt blocks when we're doing a REMAP bunmapi call Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 46/80] ACPI: Add out of bounds and numa_off protections to pxm_to_node() Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 47/80] genirq: Add stub for set_handle_irq() when !GENERIC_IRQ_MULTI_HANDLER Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 48/80] dm: change max_io_len() to use blk_max_size_offset() Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 49/80] brcmfmac: Fix warning message after dongle setup failed Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 50/80] drivers/net/wan/hdlc_fr: Correctly handle special skb->protocol values Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 51/80] bus/fsl_mc: Do not rely on caller to provide non NULL mc_io Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 52/80] ACPI: HMAT: Fix handling of changes from ACPI 6.2 to ACPI 6.3 Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 53/80] power: supply: test_power: add missing newlines when printing parameters by sysfs Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 54/80] drm/amd/display: HDMI remote sink need mode validation for Linux Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 55/80] ARC: [dts] fix the errors detected by dtbs_check Sasha Levin
2020-10-26 23:54 ` Sasha Levin [this message]
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 57/80] md/bitmap: md_bitmap_get_counter returns wrong blocks Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 58/80] bnxt_en: Log unknown link speed appropriately Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 59/80] rpmsg: glink: Use complete_all for open states Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 60/80] clk: ti: clockdomain: fix static checker warning Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 61/80] phy: marvell: comphy: Convert internal SMCC firmware return codes to errno Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 62/80] asm-generic/io.h: Fix !CONFIG_GENERIC_IOMAP pci_iounmap() implementation Sasha Levin
2020-10-26 23:54 ` [PATCH AUTOSEL 5.4 63/80] net: 9p: initialize sun_server.sun_path to have addr's value only when addr is valid Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 64/80] drivers: watchdog: rdc321x_wdt: Fix race condition bugs Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 65/80] ext4: Detect already used quota file early Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 66/80] PCI: dwc: Add link up check in dw_child_pcie_ops.map_bus() Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 67/80] KVM: PPC: Book3S HV: Do not allocate HPT for a nested guest Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 68/80] gfs2: use-after-free in sysfs deregistration Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 69/80] gfs2: add validation checks for size of superblock Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 70/80] cifs: handle -EINTR in cifs_setattr Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 71/80] arm64: dts: renesas: ulcb: add full-pwr-cycle-in-suspend into eMMC nodes Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 72/80] ARM: dts: omap4: Fix sgx clock rate for 4430 Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 73/80] memory: emif: Remove bogus debugfs error handling Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 74/80] ARM: dts: s5pv210: remove DMA controller bus node name to fix dtschema warnings Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 75/80] ARM: dts: s5pv210: move fixed clocks under root node Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 76/80] ARM: dts: s5pv210: move PMU node out of clock controller Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 77/80] ARM: dts: s5pv210: remove dedicated 'audio-subsystem' node Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 78/80] nbd: make the config put is called before the notifying the waiter Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 79/80] sgl_alloc_order: fix memory leak Sasha Levin
2020-10-26 23:55 ` [PATCH AUTOSEL 5.4 80/80] nvme-rdma: fix crash when connect rejected Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201026235516.1025100-56-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=anand.jain@oracle.com \
    --cc=dsterba@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).