Commit cccd9fb9 authored by Jan Kara's avatar Jan Kara Committed by Jens Axboe
Browse files

block: Revalidate i_bdev reference in bd_aquire()

When a device gets removed, block device inode unhashed so that it is not
used anymore (bdget() will not find it anymore). Later when a new device
gets created with the same device number, we create new block device
inode. However there may be file system device inodes whose i_bdev still
points to the original block device inode and thus we get two active
block device inodes for the same device. They will share the same
gendisk so the only visible differences will be that page caches will
not be coherent and BDIs will be different (the old block device inode
still points to unregistered BDI).

Fix the problem by checking in bd_acquire() whether i_bdev still points
to active block device inode and re-lookup the block device if not. That
way any open of a block device happening after the old device has been
removed will get correct block device inode.
Tested-by: default avatarLekshmi Pillai <>
Acked-by: default avatarTejun Heo <>
Signed-off-by: default avatarJan Kara <>
Signed-off-by: default avatarJens Axboe <>
parent d06e05c0
......@@ -1043,13 +1043,22 @@ static struct block_device *bd_acquire(struct inode *inode)
bdev = inode->i_bdev;
if (bdev) {
if (bdev && !inode_unhashed(bdev->bd_inode)) {
return bdev;
* i_bdev references block device inode that was already shut down
* (corresponding device got removed). Remove the reference and look
* up block device inode again just in case new device got
* reestablished under the same device number.
if (bdev)
bdev = bdget(inode->i_rdev);
if (bdev) {
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment