Commit 1ebe2e5f authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe
Browse files

block: remove GENHD_FL_EXT_DEVT



All modern drivers can support extra partitions using the extended
dev_t.  In fact except for the ioctl method drivers never even see
partitions in normal operation.

So remove the GENHD_FL_EXT_DEVT and allow extra partitions for all
block devices that do support partitions, and require those that
do not support partitions to explicit disallow them using
GENHD_FL_NO_PART.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20211122130625.1136848-12-hch@lst.de


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 3b5149ac
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -376,7 +376,7 @@ int disk_scan_partitions(struct gendisk *disk, fmode_t mode)
{
	struct block_device *bdev;

	if (!disk_part_scan_enabled(disk))
	if (disk->flags & GENHD_FL_NO_PART)
		return -EINVAL;
	if (disk->open_partitions)
		return -EBUSY;
@@ -438,7 +438,6 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
			return ret;
		disk->major = BLOCK_EXT_MAJOR;
		disk->first_minor = ret;
		disk->flags |= GENHD_FL_EXT_DEVT;
	}

	ret = disk_alloc_events(disk);
@@ -872,7 +871,8 @@ static ssize_t disk_ext_range_show(struct device *dev,
{
	struct gendisk *disk = dev_to_disk(dev);

	return sprintf(buf, "%d\n", disk_max_parts(disk));
	return sprintf(buf, "%d\n",
		(disk->flags & GENHD_FL_NO_PART) ? 1 : DISK_MAX_PARTS);
}

static ssize_t disk_removable_show(struct device *dev,
+4 −5
Original line number Diff line number Diff line
@@ -98,13 +98,12 @@ static void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors)
static struct parsed_partitions *allocate_partitions(struct gendisk *hd)
{
	struct parsed_partitions *state;
	int nr;
	int nr = DISK_MAX_PARTS;

	state = kzalloc(sizeof(*state), GFP_KERNEL);
	if (!state)
		return NULL;

	nr = disk_max_parts(hd);
	state->parts = vzalloc(array_size(nr, sizeof(state->parts[0])));
	if (!state->parts) {
		kfree(state);
@@ -326,7 +325,7 @@ static struct block_device *add_partition(struct gendisk *disk, int partno,

	lockdep_assert_held(&disk->open_mutex);

	if (partno >= disk_max_parts(disk))
	if (partno >= DISK_MAX_PARTS)
		return ERR_PTR(-EINVAL);

	/*
@@ -604,7 +603,7 @@ static int blk_add_partitions(struct gendisk *disk)
	struct parsed_partitions *state;
	int ret = -EAGAIN, p;

	if (!disk_part_scan_enabled(disk))
	if (disk->flags & GENHD_FL_NO_PART)
		return 0;

	state = check_partition(disk);
@@ -687,7 +686,7 @@ int bdev_disk_changed(struct gendisk *disk, bool invalidate)
	 * userspace for this particular setup.
	 */
	if (invalidate) {
		if (disk_part_scan_enabled(disk) ||
		if (!(disk->flags & GENHD_FL_NO_PART) ||
		    !(disk->flags & GENHD_FL_REMOVABLE))
			set_capacity(disk, 0);
	}
+1 −0
Original line number Diff line number Diff line
@@ -1790,6 +1790,7 @@ static int fd_alloc_disk(int drive, int system)
	disk->first_minor = drive + system;
	disk->minors = 1;
	disk->fops = &floppy_fops;
	disk->flags |= GENHD_FL_NO_PART;
	disk->events = DISK_EVENT_MEDIA_CHANGE;
	if (system)
		sprintf(disk->disk_name, "fd%d_msdos", drive);
+1 −0
Original line number Diff line number Diff line
@@ -2000,6 +2000,7 @@ static int ataflop_alloc_disk(unsigned int drive, unsigned int type)
	disk->minors = 1;
	sprintf(disk->disk_name, "fd%d", drive);
	disk->fops = &floppy_fops;
	disk->flags |= GENHD_FL_NO_PART;
	disk->events = DISK_EVENT_MEDIA_CHANGE;
	disk->private_data = &unit[drive];
	set_capacity(disk, MAX_DISK_SIZE * 2);
+0 −1
Original line number Diff line number Diff line
@@ -405,7 +405,6 @@ static int brd_alloc(int i)
	disk->minors		= max_part;
	disk->fops		= &brd_fops;
	disk->private_data	= brd;
	disk->flags		= GENHD_FL_EXT_DEVT;
	strlcpy(disk->disk_name, buf, DISK_NAME_LEN);
	set_capacity(disk, rd_size * 2);
	
Loading