]> www.infradead.org Git - users/hch/block.git/commitdiff
block: simplify the restart case in __blkdev_get
authorChristoph Hellwig <hch@lst.de>
Tue, 30 Jun 2020 12:43:53 +0000 (14:43 +0200)
committerChristoph Hellwig <hch@lst.de>
Thu, 2 Jul 2020 08:44:02 +0000 (10:44 +0200)
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>
fs/block_dev.c

index 2d2fcb50e78eac30eec79ecd650796946ceafb0e..175161359664cabe8e136628695d80f6aee61171 100644 (file)
@@ -1533,7 +1533,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
        int ret;
        int partno;
        int perm = 0;
-       bool first_open = false;
+       bool first_open = false, need_restart;
 
        if (mode & FMODE_READ)
                perm |= MAY_READ;
@@ -1549,7 +1549,7 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
        }
 
  restart:
-
+       need_restart = false;
        ret = -ENXIO;
        disk = bdev_get_gendisk(bdev, &partno);
        if (!disk)
@@ -1572,19 +1572,12 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
                        ret = 0;
                        if (disk->fops->open) {
                                ret = disk->fops->open(bdev, mode);
-                               if (ret == -ERESTARTSYS) {
-                                       /* Lost a race with 'disk' being
-                                        * deleted, try again.
-                                        * See md.c
-                                        */
-                                       disk_put_part(bdev->bd_part);
-                                       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 we lost a race with 'disk' being deleted,
+                                * try again.  See md.c
+                                */
+                               if (ret == -ERESTARTSYS)
+                                       need_restart = true;
                        }
 
                        if (!ret) {
@@ -1663,6 +1656,8 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
        mutex_unlock(&bdev->bd_mutex);
        disk_unblock_events(disk);
        put_disk_and_module(disk);
+       if (need_restart)
+               goto restart;
  out:
 
        return ret;