block: remove GENHD_FL_EXT_DEVT
authorChristoph Hellwig <hch@lst.de>
Mon, 22 Nov 2021 13:06:22 +0000 (14:06 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 29 Nov 2021 13:38:35 +0000 (06:38 -0700)
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: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20211122130625.1136848-12-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
27 files changed:
block/genhd.c
block/partitions/core.c
drivers/block/amiflop.c
drivers/block/ataflop.c
drivers/block/brd.c
drivers/block/drbd/drbd_main.c
drivers/block/floppy.c
drivers/block/loop.c
drivers/block/null_blk/main.c
drivers/block/paride/pcd.c
drivers/block/paride/pf.c
drivers/block/pktcdvd.c
drivers/block/ps3vram.c
drivers/block/rbd.c
drivers/block/swim.c
drivers/block/swim3.c
drivers/block/virtio_blk.c
drivers/block/z2ram.c
drivers/block/zram/zram_drv.c
drivers/cdrom/gdrom.c
drivers/md/dm.c
drivers/md/md.c
drivers/mmc/core/block.c
drivers/mtd/ubi/block.c
drivers/scsi/sd.c
drivers/scsi/sr.c
include/linux/genhd.h

index 50a843ee18f6107a82d56e9e795b200d4a00a399..628632537129c68af810ceace460066b9dc16647 100644 (file)
@@ -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,
index 520292fee933916cc3a6e864b93f8b60af1c2af9..c2a1635922b1c39390a971da6a1047929fbb9592 100644 (file)
@@ -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 @@ rescan:
         * 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);
        }
index bf5c124c5452adb938f51f41b2ed7061e8f19779..1eec5113d0b5b7bdd3151797a9513ddb4457bec2 100644 (file)
@@ -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);
index bf769e6e32fef92b76dffd0f94455ba9096c30b3..f3ff9babdb5cd4a00447e8fd66d8717f1a4d0618 100644 (file)
@@ -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);
index a896ee175d8638417830b0449b7515026495012a..8fe2e4289dae390d53c8607b36da88084e84a07a 100644 (file)
@@ -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);
        
index 53ba2dddba6e6e55f60628840afe810cebce2234..07b3c6093e7dbced15e5f7796f47ed40d5657111 100644 (file)
@@ -2734,6 +2734,7 @@ enum drbd_ret_code drbd_create_device(struct drbd_config_context *adm_ctx, unsig
        disk->first_minor = minor;
        disk->minors = 1;
        disk->fops = &drbd_ops;
+       disk->flags |= GENHD_FL_NO_PART;
        sprintf(disk->disk_name, "drbd%d", minor);
        disk->private_data = device;
 
index c4267da716fe621d3be21c23641a54532d6e6d10..7f0a60c4079fd121a8c18a6d8fec385c9ab34d87 100644 (file)
@@ -4503,6 +4503,7 @@ static int floppy_alloc_disk(unsigned int drive, unsigned int type)
        disk->first_minor = TOMINOR(drive) | (type << 2);
        disk->minors = 1;
        disk->fops = &floppy_fops;
+       disk->flags |= GENHD_FL_NO_PART;
        disk->events = DISK_EVENT_MEDIA_CHANGE;
        if (type)
                sprintf(disk->disk_name, "fd%d_type%d", drive, type);
index 7219d98c6fb8add0d360a6722a51e0fd0bbfa830..0954ea8cf9e3b53fba76330d7b1ab5cf730bb709 100644 (file)
@@ -2033,7 +2033,6 @@ static int loop_add(int i)
         */
        if (!part_shift)
                disk->flags |= GENHD_FL_NO_PART;
-       disk->flags |= GENHD_FL_EXT_DEVT;
        atomic_set(&lo->lo_refcnt, 0);
        mutex_init(&lo->lo_mutex);
        lo->lo_number           = i;
index eb17def1f265e888fa75d2751975c252e699d022..54f7d490f8ebb6ebf55a85d1bdae6f038b276882 100644 (file)
@@ -1850,7 +1850,6 @@ static int null_gendisk_register(struct nullb *nullb)
 
        set_capacity(disk, size);
 
-       disk->flags |= GENHD_FL_EXT_DEVT;
        disk->major             = null_major;
        disk->first_minor       = nullb->index;
        disk->minors            = 1;
index 430ee8004a514d7f66721209b3664308744e369d..255fd3d4b8a84313f5fce7aaf52651262b35449b 100644 (file)
@@ -928,6 +928,7 @@ static int pcd_init_unit(struct pcd_unit *cd, bool autoprobe, int port,
        disk->minors = 1;
        strcpy(disk->disk_name, cd->name);      /* umm... */
        disk->fops = &pcd_bdops;
+       disk->flags |= GENHD_FL_NO_PART;
        disk->events = DISK_EVENT_MEDIA_CHANGE;
        disk->event_flags = DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE;
 
index bf8d0ef41a0a2a65e871d3f1f6d97784ae3d184d..b84a6448a4f75904b64d997f0328550b42c7e4c7 100644 (file)
@@ -942,6 +942,7 @@ static int __init pf_init_unit(struct pf_unit *pf, bool autoprobe, int port,
        disk->minors = 1;
        strcpy(disk->disk_name, pf->name);
        disk->fops = &pf_fops;
+       disk->flags |= GENHD_FL_NO_PART;
        disk->events = DISK_EVENT_MEDIA_CHANGE;
        disk->private_data = pf;
 
index b53f648302c1587664cabfa04f19c7322c4797be..3af0499857ecf04ce8e25faf1feb618789727e2f 100644 (file)
@@ -2719,7 +2719,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev)
        disk->first_minor = idx;
        disk->minors = 1;
        disk->fops = &pktcdvd_ops;
-       disk->flags = GENHD_FL_REMOVABLE;
+       disk->flags = GENHD_FL_REMOVABLE | GENHD_FL_NO_PART;
        strcpy(disk->disk_name, pd->name);
        disk->private_data = pd;
 
index c1876646a4cb9ffeef1e75bf4535bb49926ea8c4..4f90819e245e9974776aa8d2b2c46662ac7ec67c 100644 (file)
@@ -742,6 +742,7 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
        priv->gendisk = gendisk;
        gendisk->major = ps3vram_major;
        gendisk->minors = 1;
+       gendisk->flags |= GENHD_FL_NO_PART;
        gendisk->fops = &ps3vram_fops;
        gendisk->private_data = dev;
        strlcpy(gendisk->disk_name, DEVICE_NAME, sizeof(gendisk->disk_name));
index 953fa134cd3db78cff006ce37931fd6a089fe8ba..8f140da1efe300b8065905158ec2cbf676e3ce97 100644 (file)
@@ -4924,12 +4924,10 @@ static int rbd_init_disk(struct rbd_device *rbd_dev)
                 rbd_dev->dev_id);
        disk->major = rbd_dev->major;
        disk->first_minor = rbd_dev->minor;
-       if (single_major) {
+       if (single_major)
                disk->minors = (1 << RBD_SINGLE_MAJOR_PART_SHIFT);
-               disk->flags |= GENHD_FL_EXT_DEVT;
-       } else {
+       else
                disk->minors = RBD_MINORS_PER_MAJOR;
-       }
        disk->fops = &rbd_bd_ops;
        disk->private_data = rbd_dev;
 
index 821594cd1315198000068808b121409b8d9e7f3c..fef65a18d56fa9f88587450cdb7abed6fcc7989b 100644 (file)
@@ -840,6 +840,7 @@ static int swim_floppy_init(struct swim_priv *swd)
                swd->unit[drive].disk->minors = 1;
                sprintf(swd->unit[drive].disk->disk_name, "fd%d", drive);
                swd->unit[drive].disk->fops = &floppy_fops;
+               swd->unit[drive].disk->flags |= GENHD_FL_NO_PART;
                swd->unit[drive].disk->events = DISK_EVENT_MEDIA_CHANGE;
                swd->unit[drive].disk->private_data = &swd->unit[drive];
                set_capacity(swd->unit[drive].disk, 2880);
index 4b91c9aa58926ceeda4856c042fd01b4bf3adc4f..6c39f2c9f806d8c68d89a8102f9b79849d97b16e 100644 (file)
@@ -1227,7 +1227,7 @@ static int swim3_attach(struct macio_dev *mdev,
        disk->fops = &floppy_fops;
        disk->private_data = fs;
        disk->events = DISK_EVENT_MEDIA_CHANGE;
-       disk->flags |= GENHD_FL_REMOVABLE;
+       disk->flags |= GENHD_FL_REMOVABLE | GENHD_FL_NO_PART;
        sprintf(disk->disk_name, "fd%d", floppy_count);
        set_capacity(disk, 2880);
        rc = add_disk(disk);
index 6ae38776e30e5049b31f45dc8b8158cf98643a4d..cfa303fa7318e6752093d8dcf7544fe2d963eebe 100644 (file)
@@ -843,7 +843,6 @@ static int virtblk_probe(struct virtio_device *vdev)
        vblk->disk->minors = 1 << PART_BITS;
        vblk->disk->private_data = vblk;
        vblk->disk->fops = &virtblk_fops;
-       vblk->disk->flags |= GENHD_FL_EXT_DEVT;
        vblk->index = index;
 
        /* configure queue flush support */
index ccc52c935fafc3be986675836e90081c8b0b2f51..7a6ed83481b8de4b793646c9777eaa74dd7eba70 100644 (file)
@@ -327,6 +327,7 @@ static int z2ram_register_disk(int minor)
        disk->major = Z2RAM_MAJOR;
        disk->first_minor = minor;
        disk->minors = 1;
+       disk->flags |= GENHD_FL_NO_PART;
        disk->fops = &z2_fops;
        if (minor)
                sprintf(disk->disk_name, "z2ram%d", minor);
index 25071126995befb16c69e2c88a590fb54dd0491b..f6da5293b913d89d64816f1b150b90766a5aced3 100644 (file)
@@ -1947,6 +1947,7 @@ static int zram_add(void)
        zram->disk->major = zram_major;
        zram->disk->first_minor = device_id;
        zram->disk->minors = 1;
+       zram->disk->flags |= GENHD_FL_NO_PART;
        zram->disk->fops = &zram_devops;
        zram->disk->private_data = zram;
        snprintf(zram->disk->disk_name, 16, "zram%d", device_id);
index d50cc1fd34d5ffd650d2bddc50cd35fa764aaf2d..faead41709bcd8da89c378f48d87bb841cc9c5aa 100644 (file)
@@ -719,6 +719,7 @@ static void probe_gdrom_setupdisk(void)
        gd.disk->major = gdrom_major;
        gd.disk->first_minor = 1;
        gd.disk->minors = 1;
+       gd.disk->flags |= GENHD_FL_NO_PART;
        strcpy(gd.disk->disk_name, GDROM_DEV_NAME);
 }
 
index 662742a310cbb434121233c682c9200bbd54ed4f..280918cdcabd30e9f3da568daa3d49d79da6f883 100644 (file)
@@ -1778,6 +1778,7 @@ static struct mapped_device *alloc_dev(int minor)
        md->disk->major = _major;
        md->disk->first_minor = minor;
        md->disk->minors = 1;
+       md->disk->flags |= GENHD_FL_NO_PART;
        md->disk->fops = &dm_blk_dops;
        md->disk->queue = md->queue;
        md->disk->private_data = md;
index 5111ed966947e2dcc3e2b01f02e6c5fad7259fcd..7fbf6f0ac01bedde5c784396d93d0c9f9c57509a 100644 (file)
@@ -5707,11 +5707,6 @@ static int md_alloc(dev_t dev, char *name)
        mddev->queue = disk->queue;
        blk_set_stacking_limits(&mddev->queue->limits);
        blk_queue_write_cache(mddev->queue, true, true);
-       /* Allow extended partitions.  This makes the
-        * 'mdp' device redundant, but we can't really
-        * remove it now.
-        */
-       disk->flags |= GENHD_FL_EXT_DEVT;
        disk->events |= DISK_EVENT_MEDIA_CHANGE;
        mddev->gendisk = disk;
        error = add_disk(disk);
index 2dd93d49d822c6b6de5543c8f26ea0e8b1e7b738..5e0960560eab766f88bf9d888622462cbcbf883a 100644 (file)
@@ -2395,7 +2395,6 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card,
        md->disk->private_data = md;
        md->parent = parent;
        set_disk_ro(md->disk, md->read_only || default_ro);
-       md->disk->flags = GENHD_FL_EXT_DEVT;
        if (area_type & (MMC_BLK_DATA_AREA_RPMB | MMC_BLK_DATA_AREA_BOOT))
                md->disk->flags |= GENHD_FL_NO_PART;
 
index 302426ab30f8df36f03e82e22d6a360b94434db3..a78fdf3b30f7e6d1d8916c5556c2a01e1f0b6563 100644 (file)
@@ -430,6 +430,7 @@ int ubiblock_create(struct ubi_volume_info *vi)
                ret = -ENODEV;
                goto out_cleanup_disk;
        }
+       gd->flags |= GENHD_FL_NO_PART;
        gd->private_data = dev;
        sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id);
        set_capacity(gd, disk_capacity);
index 65875a598d6291feb0318559678d5bdd1fc5e3f2..bba1f5dafd38718c405bbfb8c720d3ce0cfe61c7 100644 (file)
@@ -3566,7 +3566,6 @@ static int sd_probe(struct device *dev)
 
        sd_revalidate_disk(gd);
 
-       gd->flags = GENHD_FL_EXT_DEVT;
        if (sdp->removable) {
                gd->flags |= GENHD_FL_REMOVABLE;
                gd->events |= DISK_EVENT_MEDIA_CHANGE;
index 6646797a7756ea8d52db3382c40ac707cba9063e..cf093387e42a13e284b181c1f46cc27d502bcdbe 100644 (file)
@@ -684,6 +684,7 @@ static int sr_probe(struct device *dev)
        disk->minors = 1;
        sprintf(disk->disk_name, "sr%d", minor);
        disk->fops = &sr_bdops;
+       disk->flags |= GENHD_FL_NO_PART;
        disk->events = DISK_EVENT_MEDIA_CHANGE | DISK_EVENT_EJECT_REQUEST;
        disk->event_flags = DISK_EVENT_FLAG_POLL | DISK_EVENT_FLAG_UEVENT |
                                DISK_EVENT_FLAG_BLOCK_ON_EXCL_WRITE;
index 64a2f33ae9ea4bcbbf8731721d72ff0719a395c1..b8ced80178d64ecc15cbf0fa7ca25a1953069bd5 100644 (file)
@@ -46,11 +46,6 @@ struct partition_meta_info {
  * Must not be set for devices which are removed entirely when the
  * media is removed.
  *
- * ``GENHD_FL_EXT_DEVT`` (0x0040): the driver supports extended
- * dynamic ``dev_t``, i.e. it wants extended device numbers
- * (``BLOCK_EXT_MAJOR``).
- * This affects the maximum number of partitions.
- *
  * ``GENHD_FL_NO_PART`` (0x0200): partition support is disabled.
  * The kernel will not scan for partitions from add_disk, and users
  * can't add partitions manually.
@@ -64,7 +59,6 @@ struct partition_meta_info {
 #define GENHD_FL_REMOVABLE                     0x0001
 /* 2 is unused (used to be GENHD_FL_DRIVERFS) */
 /* 4 is unused (used to be GENHD_FL_MEDIA_CHANGE_NOTIFY) */
-#define GENHD_FL_EXT_DEVT                      0x0040
 #define GENHD_FL_NO_PART                       0x0200
 #define GENHD_FL_HIDDEN                                0x0400
 
@@ -94,13 +88,13 @@ struct blk_integrity {
 };
 
 struct gendisk {
-       /* major, first_minor and minors are input parameters only,
-        * don't use directly.  Use disk_devt() and disk_max_parts().
+       /*
+        * major/first_minor/minors should not be set by any new driver, the
+        * block core will take care of allocating them automatically.
         */
-       int major;                      /* major number of driver */
+       int major;
        int first_minor;
-       int minors;                     /* maximum number of minors, =1 for
-                                         * disks that can't be partitioned. */
+       int minors;
 
        char disk_name[DISK_NAME_LEN];  /* name of major driver */
 
@@ -164,18 +158,6 @@ static inline bool disk_live(struct gendisk *disk)
 #define disk_to_cdi(disk)      NULL
 #endif
 
-static inline int disk_max_parts(struct gendisk *disk)
-{
-       if (disk->flags & GENHD_FL_EXT_DEVT)
-               return DISK_MAX_PARTS;
-       return disk->minors;
-}
-
-static inline bool disk_part_scan_enabled(struct gendisk *disk)
-{
-       return disk_max_parts(disk) > 1 && !(disk->flags & GENHD_FL_NO_PART);
-}
-
 static inline dev_t disk_devt(struct gendisk *disk)
 {
        return MKDEV(disk->major, disk->first_minor);