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.
Unified · Split
| @@ -1090,11 +1090,10 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, · 1089 unmodified lines | ||
| 1090 | 1090 | * here to avoid changing device under exclusive owner. |
| 1091 | 1091 | */ |
| 1092 | 1092 | 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) | |
| 1096 | 1096 | goto out_putf; |
| 1097 | − } | |
| 1098 | 1097 | } |
| 1099 | 1098 | |
| 1100 | 1099 | error = mutex_lock_killable(&loop_ctl_mutex); |
| @@ -1027,8 +1027,8 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole, · 1026 unmodified lines | ||
| 1027 | 1027 | * RETURNS: |
| 1028 | 1028 | * 0 if @bdev can be claimed, -EBUSY otherwise. |
| 1029 | 1029 | */ |
| 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) | |
| 1032 | 1032 | { |
| 1033 | 1033 | retry: |
| 1034 | 1034 | spin_lock(&bdev_lock); |
| @@ -1055,6 +1055,7 @@ retry: · 20 unmodified lines | ||
| 1055 | 1055 | spin_unlock(&bdev_lock); |
| 1056 | 1056 | return 0; |
| 1057 | 1057 | } |
| 1058 | +EXPORT_SYMBOL_GPL(bd_prepare_to_claim); /* only for the loop driver */ | |
| 1058 | 1059 | |
| 1059 | 1060 | static struct gendisk *bdev_get_gendisk(struct block_device *bdev, int *partno) |
| 1060 | 1061 | { |
| @@ -1100,7 +1101,8 @@ static struct gendisk *bdev_get_gendisk(struct block_device *bdev, int *partno) · 39 unmodified lines | ||
| 1100 | 1101 | * Pointer to the block device containing @bdev on success, ERR_PTR() |
| 1101 | 1102 | * value on failure. |
| 1102 | 1103 | */ |
| 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) | |
| 1104 | 1106 | { |
| 1105 | 1107 | struct gendisk *disk; |
| 1106 | 1108 | struct block_device *whole; |
| @@ -1141,7 +1143,6 @@ struct block_device *bd_start_claiming(struct block_device *bdev, void *holder) · 34 unmodified lines | ||
| 1141 | 1143 | |
| 1142 | 1144 | return whole; |
| 1143 | 1145 | } |
| 1144 | −EXPORT_SYMBOL(bd_start_claiming); | |
| 1145 | 1146 | |
| 1146 | 1147 | static void bd_clear_claiming(struct block_device *whole, void *holder) |
| 1147 | 1148 | { |
| @@ -1919,7 +1919,8 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder); · 1918 unmodified lines | ||
| 1919 | 1919 | struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, |
| 1920 | 1920 | void *holder); |
| 1921 | 1921 | 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); | |
| 1923 | 1924 | void bd_abort_claiming(struct block_device *bdev, struct block_device *whole, |
| 1924 | 1925 | void *holder); |
| 1925 | 1926 | void blkdev_put(struct block_device *bdev, fmode_t mode); |