]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
block: Revalidate i_bdev reference in bd_aquire()
authorJan Kara <jack@suse.cz>
Tue, 21 Feb 2017 17:09:48 +0000 (18:09 +0100)
committerThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Thu, 27 Apr 2017 13:04:16 +0000 (10:04 -0300)
BugLink: http://bugs.launchpad.net/bugs/1659111
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: Lekshmi Pillai <lekshmicpillai@in.ibm.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jens Axboe <axboe@fb.com>
(back ported from commit cccd9fb9ec960e343b2f354c4613e49f5a1d8371)

Conflicts:
fs/block_dev.c

Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
Acked-by: Seth Forshee <seth.forshee@canonical.com>
Acked-by: Brad Figg <brad.figg@canonical.com>
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
fs/block_dev.c

index 3783ea8d36810c420f3e1cc5f279ec2dceaf0b5f..ca76e189088cd986e68b2f84dcdd369cf6217118 100644 (file)
@@ -713,13 +713,22 @@ static struct block_device *bd_acquire(struct inode *inode)
 
        spin_lock(&bdev_lock);
        bdev = inode->i_bdev;
-       if (bdev) {
+       if (bdev && !inode_unhashed(bdev->bd_inode)) {
                ihold(bdev->bd_inode);
                spin_unlock(&bdev_lock);
                return bdev;
        }
        spin_unlock(&bdev_lock);
 
+       /*
+        * 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)
+               bd_forget(inode);
+
        bdev = bdget(inode->i_rdev);
        if (bdev) {
                spin_lock(&bdev_lock);