block: pass a gendisk to bdev_{add,del,resize}_partition
PATCH 1/1 block: pass a gendisk to bdev_{add,del,resize}_partition
These helpers deal with partition tables and thus logically operate on the gendisk.
Signed-off-by Christoph Hellwig <[email protected]>
--- block/blk.h | 6 +++--- block/ioctl.c | 7 ++++--- block/partitions/core.c | 36 ++++++++++++++++++------------------ 3 files changed, 25 insertions(+), 24 deletions(-)
block/blk.h +3 -3
@@ -348,10 +348,10 @@ char *disk_name(struct gendisk *hd, int partno, char *buf);#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, +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, +int bdev_del_partition (struct gendisk *disk,int partno); +int bdev_resize_partition (struct gendisk *disk,int partno,sector_t start,sector_t length); int bio_add_hw_page(struct request_queue *q, struct bio *bio,
block/ioctl.c +4 -3
@@ -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;
@@ -30,7 +31,7 @@ static int blkpg_do_ioctl(struct block_device *bdev,return -EINVAL ;if (op ==BLKPG_DEL_PARTITION ) -return bdev_del_partition (bdev, p.pno); +return bdev_del_partition (disk, p.pno); start = p.start >>SECTOR_SHIFT ; length = p.length >>SECTOR_SHIFT ;
@@ -40,9 +41,9 @@ 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); +return bdev_resize_partition (disk, p.pno, start, length);default :return -EINVAL ; }
block/partitions/core.c +18 -18
@@ -449,30 +449,30 @@ 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; -mutex_lock (&bdev->bd_disk->open_mutex); -if (partition_overlaps (bdev->bd_disk, start, length,-1 )) { -mutex_unlock (&bdev->bd_disk->open_mutex); +mutex_lock (&disk->open_mutex); +if (partition_overlaps (disk, start, length,-1 )) { +mutex_unlock (&disk->open_mutex);return -EBUSY ; } - part =add_partition (bdev->bd_disk, partno, start, length, -ADDPART_FLAG_NONE ,NULL ); -mutex_unlock (&bdev->bd_disk->open_mutex); + part =add_partition (disk, partno, start, length,ADDPART_FLAG_NONE , +NULL ); +mutex_unlock (&disk->open_mutex);return PTR_ERR_OR_ZERO (part); } -int bdev_del_partition (struct block_device *bdev,int partno) +int bdev_del_partition (struct gendisk *disk,int partno) {struct block_device *part =NULL ;int ret = -ENXIO ; -mutex_lock (&bdev->bd_disk->open_mutex); - part =xa_load (&bdev->bd_disk->part_tbl, partno); +mutex_lock (&disk->open_mutex); + part =xa_load (&disk->part_tbl, partno);if (!part) goto out_unlock;
@@ -483,18 +483,18 @@ int bdev_del_partition(struct block_device *bdev, int partno)delete_partition (part); ret =0 ; out_unlock: -mutex_unlock (&bdev->bd_disk->open_mutex); +mutex_unlock (&disk->open_mutex);return ret; } -int bdev_resize_partition (struct block_device *bdev,int partno, -sector_t start,sector_t length) +int bdev_resize_partition (struct gendisk *disk,int partno,sector_t start, +sector_t length) {struct block_device *part =NULL ;int ret = -ENXIO ; -mutex_lock (&bdev->bd_disk->open_mutex); - part =xa_load (&bdev->bd_disk->part_tbl, partno); +mutex_lock (&disk->open_mutex); + part =xa_load (&disk->part_tbl, partno);if (!part) goto out_unlock;
@@ -503,14 +503,14 @@ int bdev_resize_partition(struct block_device *bdev, int partno, goto out_unlock; ret = -EBUSY ; -if (partition_overlaps (bdev->bd_disk, start, length, partno)) +if (partition_overlaps (disk, start, length, partno)) goto out_unlock;bdev_set_nr_sectors (part, length); ret =0 ; out_unlock: -mutex_unlock (&bdev->bd_disk->open_mutex); +mutex_unlock (&disk->open_mutex);return ret; }
Signature · 1 line
2.30.2