History

block: use bd_prepare_to_claim directly in the loop driver

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.

Christoph Hellwig committed 6 years ago

Commit ecbe6bc1 parent 58e46ed3 files · +10 −9Browse files

Unified · Split

3 files
  1. drivers/block/loop.c +3 −4
  2. fs/block_dev.c +5 −4
  3. include/linux/blkdev.h +2 −1
drivers/block/loop.c+3−4
@@ -1090,11 +1090,10 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, · 1089 unmodified lines
10901090 * here to avoid changing device under exclusive owner.
10911091 */
10921092 if (!(mode & FMODE_EXCL)) {
1093− claimed_bdev = bd_start_claiming(bdev, loop_configure);
1094− if (IS_ERR(claimed_bdev)) {
1095− error = PTR_ERR(claimed_bdev);
1093+ claimed_bdev = bdev->bd_contains;
1094+ error = bd_prepare_to_claim(bdev, claimed_bdev, loop_configure);
1095+ if (error)
10961096 goto out_putf;
1097− }
10981097 }
10991098
11001099 error = mutex_lock_killable(&loop_ctl_mutex);
fs/block_dev.c+5−4
@@ -1027,8 +1027,8 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole, · 1026 unmodified lines
10271027 * RETURNS:
10281028 * 0 if @bdev can be claimed, -EBUSY otherwise.
10291029 */
1030−static int bd_prepare_to_claim(struct block_device *bdev,
1031− struct block_device *whole, void *holder)
1030+int bd_prepare_to_claim(struct block_device *bdev, struct block_device *whole,
1031+ void *holder)
10321032 {
10331033 retry:
10341034 spin_lock(&bdev_lock);
@@ -1055,6 +1055,7 @@ retry: · 20 unmodified lines
10551055 spin_unlock(&bdev_lock);
10561056 return 0;
10571057 }
1058+EXPORT_SYMBOL_GPL(bd_prepare_to_claim); /* only for the loop driver */
10581059
10591060 static struct gendisk *bdev_get_gendisk(struct block_device *bdev, int *partno)
10601061 {
@@ -1100,7 +1101,8 @@ static struct gendisk *bdev_get_gendisk(struct block_device *bdev, int *partno) · 39 unmodified lines
11001101 * Pointer to the block device containing @bdev on success, ERR_PTR()
11011102 * value on failure.
11021103 */
1103−struct block_device *bd_start_claiming(struct block_device *bdev, void *holder)
1104+static struct block_device *bd_start_claiming(struct block_device *bdev,
1105+ void *holder)
11041106 {
11051107 struct gendisk *disk;
11061108 struct block_device *whole;
@@ -1141,7 +1143,6 @@ struct block_device *bd_start_claiming(struct block_device *bdev, void *holder) · 34 unmodified lines
11411143
11421144 return whole;
11431145 }
1144−EXPORT_SYMBOL(bd_start_claiming);
11451146
11461147 static void bd_clear_claiming(struct block_device *whole, void *holder)
11471148 {
include/linux/blkdev.h+2−1
@@ -1919,7 +1919,8 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder); · 1918 unmodified lines
19191919 struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
19201920 void *holder);
19211921 struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder);
1922−struct block_device *bd_start_claiming(struct block_device *bdev, void *holder);
1922+int bd_prepare_to_claim(struct block_device *bdev, struct block_device *whole,
1923+ void *holder);
19231924 void bd_abort_claiming(struct block_device *bdev, struct block_device *whole,
19241925 void *holder);
19251926 void blkdev_put(struct block_device *bdev, fmode_t mode);