block: use bd_prepare_to_claim directly in the loop driver
authorChristoph Hellwig <hch@lst.de>
Thu, 16 Jul 2020 14:33:09 +0000 (16:33 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 16 Jul 2020 15:35:44 +0000 (09:35 -0600)
The arcane magic in bd_start_claiming is only needed to be able to claim
a block_device that hasn't been fully set up.  Switch the loop driver
that claims from the ioctl path with a fully set up struct block_device
to just use the much simpler bd_prepare_to_claim directly.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/loop.c
fs/block_dev.c
include/linux/blkdev.h

index a943207705ddf11275fa8cebe6ba6d930f0dfe6c..d181601462260b3fb126149e011be4f96d882f95 100644 (file)
@@ -1090,11 +1090,10 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
         * here to avoid changing device under exclusive owner.
         */
        if (!(mode & FMODE_EXCL)) {
-               claimed_bdev = bd_start_claiming(bdev, loop_configure);
-               if (IS_ERR(claimed_bdev)) {
-                       error = PTR_ERR(claimed_bdev);
+               claimed_bdev = bdev->bd_contains;
+               error = bd_prepare_to_claim(bdev, claimed_bdev, loop_configure);
+               if (error)
                        goto out_putf;
-               }
        }
 
        error = mutex_lock_killable(&loop_ctl_mutex);
index b7b2ee4b288ae9e8436b82c402dbf57b38d677ec..ee80bd81af748d77a93dd5e5559b82b20c2bf7c6 100644 (file)
@@ -1027,8 +1027,8 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
  * RETURNS:
  * 0 if @bdev can be claimed, -EBUSY otherwise.
  */
-static int bd_prepare_to_claim(struct block_device *bdev,
-                              struct block_device *whole, void *holder)
+int bd_prepare_to_claim(struct block_device *bdev, struct block_device *whole,
+               void *holder)
 {
 retry:
        spin_lock(&bdev_lock);
@@ -1055,6 +1055,7 @@ retry:
        spin_unlock(&bdev_lock);
        return 0;
 }
+EXPORT_SYMBOL_GPL(bd_prepare_to_claim); /* only for the loop driver */
 
 static struct gendisk *bdev_get_gendisk(struct block_device *bdev, int *partno)
 {
@@ -1100,7 +1101,8 @@ static struct gendisk *bdev_get_gendisk(struct block_device *bdev, int *partno)
  * Pointer to the block device containing @bdev on success, ERR_PTR()
  * value on failure.
  */
-struct block_device *bd_start_claiming(struct block_device *bdev, void *holder)
+static struct block_device *bd_start_claiming(struct block_device *bdev,
+               void *holder)
 {
        struct gendisk *disk;
        struct block_device *whole;
@@ -1141,7 +1143,6 @@ struct block_device *bd_start_claiming(struct block_device *bdev, void *holder)
 
        return whole;
 }
-EXPORT_SYMBOL(bd_start_claiming);
 
 static void bd_clear_claiming(struct block_device *whole, void *holder)
 {
index 71173a1ffa8b8727c9fc6d3287d90b5d271de7b0..06995b96e9467962c2192cdf48bb886449dd426d 100644 (file)
@@ -1919,7 +1919,8 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder);
 struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
                void *holder);
 struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder);
-struct block_device *bd_start_claiming(struct block_device *bdev, void *holder);
+int bd_prepare_to_claim(struct block_device *bdev, struct block_device *whole,
+               void *holder);
 void bd_abort_claiming(struct block_device *bdev, struct block_device *whole,
                void *holder);
 void blkdev_put(struct block_device *bdev, fmode_t mode);