Opening a block device needs to ensure it is fully present instead of
just the allocated memory. Switch from an inode reference as obtained
by bdget to a full device model reference.
In fact we should not use inode references for anything in the block
layer. There are three users left, two can be trivially removed
and the third (xen-blkfront) is a complete mess that needs more
attention.
Signed-off-by: Christoph Hellwig <hch@lst.de>
goto bdput;
if ((disk->flags & (GENHD_FL_UP | GENHD_FL_HIDDEN)) != GENHD_FL_UP)
goto put_disk;
- if (!try_module_get(bdev->bd_disk->fops->owner))
+ if (!try_module_get(disk->fops->owner))
goto put_disk;
+
+ /* switch to a device model reference instead of the inode one: */
+ if (!kobject_get_unless_zero(&bdev->bd_device.kobj))
+ goto put_module;
+ bdput(bdev);
return bdev;
+put_module:
+ module_put(disk->fops->owner);
put_disk:
put_disk(disk);
bdput:
{
module_put(bdev->bd_disk->fops->owner);
put_disk(bdev->bd_disk);
- bdput(bdev);
+ put_device(&bdev->bd_device);
}
/**