block: switch bdgrab to use igrab

All of the current callers already have a reference, but to prepare for
additional users ensure bdgrab returns NULL if the block device is being
freed.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig 2020-11-27 16:45:27 +01:00 committed by Jens Axboe
parent 612c6aa781
commit 3a4174e686

View File

@ -894,10 +894,14 @@ static struct block_device *bdget(dev_t dev)
/**
* bdgrab -- Grab a reference to an already referenced block device
* @bdev: Block device to grab a reference to.
*
* Returns the block_device with an additional reference when successful,
* or NULL if the inode is already beeing freed.
*/
struct block_device *bdgrab(struct block_device *bdev)
{
ihold(bdev->bd_inode);
if (!igrab(bdev->bd_inode))
return NULL;
return bdev;
}
EXPORT_SYMBOL(bdgrab);