mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-11 15:49:56 +00:00
block: simplify the restart case in __blkdev_get
Insted of duplicating all the cleanup logic jump to the code that cleans up anyway, and restart after that. Signed-off-by: Christoph Hellwig <hch@lst.de> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
parent
e791ee6885
commit
c5638ab417
@ -1517,7 +1517,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
|
|||||||
int ret;
|
int ret;
|
||||||
int partno;
|
int partno;
|
||||||
int perm = 0;
|
int perm = 0;
|
||||||
bool first_open = false;
|
bool first_open = false, need_restart;
|
||||||
|
|
||||||
if (mode & FMODE_READ)
|
if (mode & FMODE_READ)
|
||||||
perm |= MAY_READ;
|
perm |= MAY_READ;
|
||||||
@ -1533,7 +1533,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
|
|||||||
}
|
}
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
|
need_restart = false;
|
||||||
ret = -ENXIO;
|
ret = -ENXIO;
|
||||||
disk = bdev_get_gendisk(bdev, &partno);
|
disk = bdev_get_gendisk(bdev, &partno);
|
||||||
if (!disk)
|
if (!disk)
|
||||||
@ -1556,19 +1556,12 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
if (disk->fops->open) {
|
if (disk->fops->open) {
|
||||||
ret = disk->fops->open(bdev, mode);
|
ret = disk->fops->open(bdev, mode);
|
||||||
if (ret == -ERESTARTSYS) {
|
/*
|
||||||
/* Lost a race with 'disk' being
|
* If we lost a race with 'disk' being deleted,
|
||||||
* deleted, try again.
|
* try again. See md.c
|
||||||
* See md.c
|
*/
|
||||||
*/
|
if (ret == -ERESTARTSYS)
|
||||||
disk_put_part(bdev->bd_part);
|
need_restart = true;
|
||||||
bdev->bd_part = NULL;
|
|
||||||
bdev->bd_disk = NULL;
|
|
||||||
mutex_unlock(&bdev->bd_mutex);
|
|
||||||
disk_unblock_events(disk);
|
|
||||||
put_disk_and_module(disk);
|
|
||||||
goto restart;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
@ -1647,6 +1640,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
|
|||||||
mutex_unlock(&bdev->bd_mutex);
|
mutex_unlock(&bdev->bd_mutex);
|
||||||
disk_unblock_events(disk);
|
disk_unblock_events(disk);
|
||||||
put_disk_and_module(disk);
|
put_disk_and_module(disk);
|
||||||
|
if (need_restart)
|
||||||
|
goto restart;
|
||||||
out:
|
out:
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user