block: pass a gendisk to bdev_add_partition
authorChristoph Hellwig <hch@lst.de>
Tue, 10 Aug 2021 15:45:10 +0000 (17:45 +0200)
committerJens Axboe <axboe@kernel.dk>
Thu, 12 Aug 2021 16:31:35 +0000 (10:31 -0600)
bdev_add_partition can only operate on the whole device.  Make that clear
by passing a gendisk instead of a block_device.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20210810154512.1809898-3-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/blk.h
block/ioctl.c
block/partitions/core.c

index 56f33fbcde59ebbd52c0440ed2ae07e06b10fbd3..c0486f609978d452e3d98b0344512033c60cafe5 100644 (file)
@@ -347,8 +347,8 @@ void blk_free_ext_minor(unsigned int minor);
 #define ADDPART_FLAG_NONE      0
 #define ADDPART_FLAG_RAID      1
 #define ADDPART_FLAG_WHOLEDISK 2
-int bdev_add_partition(struct block_device *bdev, int partno,
-               sector_t start, sector_t length);
+int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
+               sector_t length);
 int bdev_del_partition(struct block_device *bdev, int partno);
 int bdev_resize_partition(struct block_device *bdev, int partno,
                sector_t start, sector_t length);
index fff161eaab42ebb826f2317bbc7efabbdabf1053..36e0ec76b3b245dbbe008d2aa4093368df415584 100644 (file)
@@ -16,6 +16,7 @@
 static int blkpg_do_ioctl(struct block_device *bdev,
                          struct blkpg_partition __user *upart, int op)
 {
+       struct gendisk *disk = bdev->bd_disk;
        struct blkpg_partition p;
        long long start, length;
 
@@ -40,7 +41,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,
                /* check if partition is aligned to blocksize */
                if (p.start & (bdev_logical_block_size(bdev) - 1))
                        return -EINVAL;
-               return bdev_add_partition(bdev, p.pno, start, length);
+               return bdev_add_partition(disk, p.pno, start, length);
        case BLKPG_RESIZE_PARTITION:
                return bdev_resize_partition(bdev, p.pno, start, length);
        default:
index 5dd1cd1a163dca472e7eb30f7127c404a722ea99..7b227c11429778e18115b3f72de6cf4ab44542cf 100644 (file)
@@ -451,11 +451,10 @@ static bool partition_overlaps(struct gendisk *disk, sector_t start,
        return overlap;
 }
 
-int bdev_add_partition(struct block_device *bdev, int partno,
-               sector_t start, sector_t length)
+int bdev_add_partition(struct gendisk *disk, int partno, sector_t start,
+               sector_t length)
 {
        struct block_device *part;
-       struct gendisk *disk = bdev->bd_disk;
        int ret;
 
        mutex_lock(&disk->open_mutex);