Deadlock scenario for __btrfs_map_lock(), and remove the extra mirror (from target device) in the future.
Hi,
During my scrub rework (read path using btrfs_submit_bio()), I hit a deadlock situation which can happen in replace.
Although this situation can only happen when calling btrfs_map_block() during replace, currently we didn't do that inside scrub, so it's not possible to hit yet.
But it should be possible if we trigger read-repair during replace.
This happens in the following sequence:
1. We found the error in the sector
2. We need to read from the next mirror
3. We can use the extra mirror from replace target device
4. We call btrfs_map_block() for the extra mirror
The the following call chain happens:
__btrfs_map_block(mirror_num = 2)
|- down_read(&dev_replace->rwsem);
`- get_extra_mirror_from_replace()
`- __btrfs_map_block()
`- down_read(&dev_replace->rwsem);I can understand removing the ability of using replace device as a target may be too large a change.
But we should at least not call __btrfs_map_block() inside __btrfs_map_block()...
In the long run, I'd say using replace target device as an extra mirror is not that beneficial, and can be removed for cleaner code.
Thanks,
Qu