]> git.baikalelectronics.ru Git - kernel.git/commit
btrfs: Fix bug for misused dev_t when lookup in dev state hash table.
authorGu JinXiang <gujx@cn.fujitsu.com>
Thu, 19 Oct 2017 01:49:27 +0000 (09:49 +0800)
committerDavid Sterba <dsterba@suse.com>
Wed, 1 Nov 2017 19:45:36 +0000 (20:45 +0100)
commit173959d297fb31b1e79088b2069717abbc93dc97
tree4e555d032e11bdb272ce1c5ed4117e78d0fad052
parent2fea6214f72d0a8d9e904f82d72ae051f1301f19
btrfs: Fix bug for misused dev_t when lookup in dev state hash table.

Fix bug of commit 6e9c1b27ad6b ("block: replace bi_bdev with a gendisk
pointer and partitions index").

bio_dev(bio) is used to find the dev state in function
__btrfsic_submit_bio. But when dev_state is added to the hashtable, it
is using dev_t of block_device.

bio_dev(bio) returns a dev_t of part0 which is different from dev_t in
block_device(bd_dev). bd_dev in block_device represents the exact
partition.

block_device.bd_dev =
bio->bi_partno (same as block_device.bd_partno) + bio_dev(bio).

When adding a dev_state into hashtable, we use the exact partition dev_t.
So when looking it up, it should also use the exact partition dev_t.

Reproducer of this bug:

Use MOUNT_OPTIONS="-o check_int" and run btrfs/001 in fstests.
Then there will be WARNING like below.

WARNING:
btrfs: attempt to write superblock which references block M @29523968 (sda7     /1111654400/2) which is never written!

Signed-off-by: Gu JinXiang <gujx@cn.fujitsu.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/check-integrity.c