* [PATCH v2] btrfs: Fix bug for misused dev_t when lookup in dev state hash table.
@ 2017-10-19 1:49 Gu Jinxiang
2017-10-30 13:16 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Gu Jinxiang @ 2017-10-19 1:49 UTC (permalink / raw)
To: linux-btrfs; +Cc: hch, Gu JinXiang
From: Gu JinXiang <gujx@cn.fujitsu.com>
Fix bug of commit 74d46992e0d9
("block: replace bi_bdev with a gendisk pointer and partitions index").
In this modify, use bio_dev(bio) to find dev state in function
__btrfsic_submit_bio. But when dev_state added to 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 add a dev_state into hashtable it is using the exact partition's dev_t.
So when lookup it, it should also use the exact partition's dev_t.
Reproduce of this bug:
Use MOUNT_OPTIONS="-o check_int" when run btrfs/001 in xfstest.
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!
changelog:
v1->v2: Add explanation that bio_dev(bio) is different with block_device(bd_dev).
Signed-off-by: Gu JinXiang <gujx@cn.fujitsu.com>
---
fs/btrfs/check-integrity.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index fb07e3c22b9a..02f9eb83173f 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -2803,7 +2803,7 @@ static void __btrfsic_submit_bio(struct bio *bio)
mutex_lock(&btrfsic_mutex);
/* since btrfsic_submit_bio() is also called before
* btrfsic_mount(), this might return NULL */
- dev_state = btrfsic_dev_state_lookup(bio_dev(bio));
+ dev_state = btrfsic_dev_state_lookup(bio_dev(bio) + bio->bi_partno);
if (NULL != dev_state &&
(bio_op(bio) == REQ_OP_WRITE) && bio_has_data(bio)) {
unsigned int i = 0;
--
2.13.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] btrfs: Fix bug for misused dev_t when lookup in dev state hash table.
2017-10-19 1:49 [PATCH v2] btrfs: Fix bug for misused dev_t when lookup in dev state hash table Gu Jinxiang
@ 2017-10-30 13:16 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2017-10-30 13:16 UTC (permalink / raw)
To: Gu Jinxiang; +Cc: linux-btrfs, hch
On Thu, Oct 19, 2017 at 09:49:27AM +0800, Gu Jinxiang wrote:
> From: Gu JinXiang <gujx@cn.fujitsu.com>
>
> Fix bug of commit 74d46992e0d9
> ("block: replace bi_bdev with a gendisk pointer and partitions index").
>
> In this modify, use bio_dev(bio) to find dev state in function
> __btrfsic_submit_bio. But when dev_state added to 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 add a dev_state into hashtable it is using the exact partition's dev_t.
> So when lookup it, it should also use the exact partition's dev_t.
>
> Reproduce of this bug:
> Use MOUNT_OPTIONS="-o check_int" when run btrfs/001 in xfstest.
> 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!
>
> changelog:
> v1->v2: Add explanation that bio_dev(bio) is different with block_device(bd_dev).
>
> Signed-off-by: Gu JinXiang <gujx@cn.fujitsu.com>
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-10-30 13:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-19 1:49 [PATCH v2] btrfs: Fix bug for misused dev_t when lookup in dev state hash table Gu Jinxiang
2017-10-30 13:16 ` David Sterba
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).