btrfs-progs: fix BUG_ON when all devices under seed fs are missing
authorGui Hecheng <guihc.fnst@cn.fujitsu.com>
Mon, 6 Oct 2014 10:17:49 +0000 (18:17 +0800)
committerDavid Sterba <dsterba@suse.cz>
Fri, 10 Oct 2014 08:38:38 +0000 (10:38 +0200)
commitcb37bf83cc583dfe1e22344049a649b363228509
tree6bdd250aa0fcc4261a84352a9eaee99b6c080b61
parent0cf497719cf8d2c6f7967a386a7b54b0119fd1b4
btrfs-progs: fix BUG_ON when all devices under seed fs are missing

Steps to reproduce:
# mkfs.btrfs -f /dev/sda[1-2]
# btrfstune -S 1 /dev/sda1
# mount /dev/sda /mnt
# btrfs dev add /dev/sda3 /mnt
# umount /mnt
# mkfs.ext4 /dev/sda1 // kill seed dev
# mkfs.ext4 /dev/sda2 // kill seed dev
# btrfs-debug-tree /dev/sda3 <== BUG_ON
Output msg:
volumes.c:1824: btrfs_read_chunk_tree: Assertion `ret` failed.
btrfs-debug-tree[0x41cb36]
btrfs-debug-tree(btrfs_read_chunk_tree+0x3ca)
btrfs-debug-tree(btrfs_setup_chunk_tree_and_device_map
btrfs-debug-tree[0x40f695]
btrfs-debug-tree(open_ctree_fs_info+0x86)
btrfs-debug-tree(main+0x12d)
/lib64/libc.so.6(__libc_start_main+0xf5)
btrfs-debug-tree[0x4062e9]

This BUG_ON complains about a failed @read_one_dev() call when
@open_seed_devices() failed to find the seed @fs_devices object
for a dev_item in chunk tree.
In this case, just insert a "shadow" @fs_devices with the fsid in
dev_item shall make no harm since no other tools will try to
make use of the stuff that the "shadow" @fs_devices possesses
after its creation.

After apply this commit, btrfs-debug-tree will report unable
to open the device.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
volumes.c