]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
block: switch ->getgeo() to struct gendisk
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 22 May 2024 02:19:55 +0000 (22:19 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 13 Aug 2025 06:59:29 +0000 (02:59 -0400)
Instances are happier that way and it makes more sense anyway -
the only part of the result that is related to partition we are given
is the start sector, and that has been filled in by the caller.

Everything else is a function of the disk.  Only one instance
(DASD) is ever looking at anything other than bdev->bd_disk and
that one is trivial to adjust.

Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
27 files changed:
Documentation/filesystems/locking.rst
arch/m68k/emu/nfblock.c
arch/um/drivers/ubd_kern.c
block/ioctl.c
block/partitions/ibm.c
drivers/block/amiflop.c
drivers/block/aoe/aoeblk.c
drivers/block/floppy.c
drivers/block/mtip32xx/mtip32xx.c
drivers/block/rnbd/rnbd-clt.c
drivers/block/sunvdc.c
drivers/block/swim.c
drivers/block/virtio_blk.c
drivers/block/xen-blkfront.c
drivers/md/dm.c
drivers/md/md.c
drivers/memstick/core/ms_block.c
drivers/memstick/core/mspro_block.c
drivers/mmc/core/block.c
drivers/mtd/mtd_blkdevs.c
drivers/mtd/ubi/block.c
drivers/nvdimm/btt.c
drivers/nvme/host/core.c
drivers/nvme/host/nvme.h
drivers/s390/block/dasd.c
drivers/scsi/sd.c
include/linux/blkdev.h

index aa287ccdac2fd9f3a33ef769f81dbd7c01e54f72..77704fde98457423beae7ff00525a7383e37132b 100644 (file)
@@ -443,7 +443,7 @@ prototypes::
        int (*direct_access) (struct block_device *, sector_t, void **,
                                unsigned long *);
        void (*unlock_native_capacity) (struct gendisk *);
-       int (*getgeo)(struct block_device *, struct hd_geometry *);
+       int (*getgeo)(struct gendisk *, struct hd_geometry *);
        void (*swap_slot_free_notify) (struct block_device *, unsigned long);
 
 locking rules:
index 83410f8184ec9a22f995a4c7a5e63766944a52d8..94a4fadc651a0c8afce1e635334b77aa0bdeb680 100644 (file)
@@ -77,9 +77,9 @@ static void nfhd_submit_bio(struct bio *bio)
        bio_endio(bio);
 }
 
-static int nfhd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int nfhd_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct nfhd_device *dev = bdev->bd_disk->private_data;
+       struct nfhd_device *dev = disk->private_data;
 
        geo->cylinders = dev->blocks >> (6 - dev->bshift);
        geo->heads = 4;
index 4de6613e7468c7c1fc0720a3600c1e37ee7c7768..f2b2feeeb4553a94bf86a90888006336a33b93a4 100644 (file)
@@ -108,7 +108,7 @@ static DEFINE_MUTEX(ubd_lock);
 
 static int ubd_ioctl(struct block_device *bdev, blk_mode_t mode,
                     unsigned int cmd, unsigned long arg);
-static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo);
+static int ubd_getgeo(struct gendisk *disk, struct hd_geometry *geo);
 
 #define MAX_DEV (16)
 
@@ -1324,9 +1324,9 @@ static blk_status_t ubd_queue_rq(struct blk_mq_hw_ctx *hctx,
        return res;
 }
 
-static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int ubd_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct ubd *ubd_dev = bdev->bd_disk->private_data;
+       struct ubd *ubd_dev = disk->private_data;
 
        geo->heads = 128;
        geo->sectors = 32;
index f7b0006ca45d775d5bb56a5f7382c1836e44a6bc..a14304f737c51d9236974cc60261897a5478409e 100644 (file)
@@ -481,7 +481,7 @@ static int blkdev_getgeo(struct block_device *bdev,
         */
        memset(&geo, 0, sizeof(geo));
        geo.start = get_start_sect(bdev);
-       ret = disk->fops->getgeo(bdev, &geo);
+       ret = disk->fops->getgeo(disk, &geo);
        if (ret)
                return ret;
        if (copy_to_user(argp, &geo, sizeof(geo)))
@@ -515,7 +515,7 @@ static int compat_hdio_getgeo(struct block_device *bdev,
         * want to override it.
         */
        geo.start = get_start_sect(bdev);
-       ret = disk->fops->getgeo(bdev, &geo);
+       ret = disk->fops->getgeo(disk, &geo);
        if (ret)
                return ret;
 
index 82d9c4c3fb41d5b1cb76976edc7b57bbf6188d89..631291fbb356b88ef9b2ab70581e63022554a8b9 100644 (file)
@@ -358,7 +358,7 @@ int ibm_partition(struct parsed_partitions *state)
                goto out_nolab;
        /* set start if not filled by getgeo function e.g. virtblk */
        geo->start = get_start_sect(bdev);
-       if (disk->fops->getgeo(bdev, geo))
+       if (disk->fops->getgeo(disk, geo))
                goto out_freeall;
        if (!fn || fn(disk, info)) {
                kfree(info);
index 6357d86eafdcbce85211037c98b57ba375ac5fca..2932b6653b6f0d3df310017146d66bd1a6796603 100644 (file)
@@ -1523,13 +1523,13 @@ static blk_status_t amiflop_queue_rq(struct blk_mq_hw_ctx *hctx,
        return BLK_STS_OK;
 }
 
-static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int fd_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       int drive = MINOR(bdev->bd_dev) & 3;
+       struct amiga_floppy_struct *p = disk->private_data;
 
-       geo->heads = unit[drive].type->heads;
-       geo->sectors = unit[drive].dtype->sects * unit[drive].type->sect_mult;
-       geo->cylinders = unit[drive].type->tracks;
+       geo->heads = p->type->heads;
+       geo->sectors = p->dtype->sects * p->type->sect_mult;
+       geo->cylinders = p->type->tracks;
        return 0;
 }
 
index 00b74a84532888cc222abdb1f62d78ce75dbee21..34ead75e7e024368acef35f97f23866b22792581 100644 (file)
@@ -269,9 +269,9 @@ static blk_status_t aoeblk_queue_rq(struct blk_mq_hw_ctx *hctx,
 }
 
 static int
-aoeblk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+aoeblk_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct aoedev *d = bdev->bd_disk->private_data;
+       struct aoedev *d = disk->private_data;
 
        if ((d->flags & DEVFL_UP) == 0) {
                printk(KERN_ERR "aoe: disk not up\n");
index 24be0c2c4075c5c61e2ce976421e26edeeed3f69..eb125a36ec2435900602fab5441730ffa00ba8ab 100644 (file)
@@ -3363,9 +3363,9 @@ static int get_floppy_geometry(int drive, int type, struct floppy_struct **g)
        return 0;
 }
 
-static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int fd_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       int drive = (long)bdev->bd_disk->private_data;
+       int drive = (long)disk->private_data;
        int type = ITYPE(drive_state[drive].fd_device);
        struct floppy_struct *g;
        int ret;
index 8fc7761397bd7a78435605a1d1b8ef0d4eb18205..567192e371a8f9b4aee9c72c18dd98125af03f05 100644 (file)
@@ -3148,17 +3148,17 @@ static int mtip_block_compat_ioctl(struct block_device *dev,
  * that each partition is also 4KB aligned. Non-aligned partitions adversely
  * affects performance.
  *
- * @dev Pointer to the block_device strucutre.
+ * @disk Pointer to the gendisk strucutre.
  * @geo Pointer to a hd_geometry structure.
  *
  * return value
  *     0       Operation completed successfully.
  *     -ENOTTY An error occurred while reading the drive capacity.
  */
-static int mtip_block_getgeo(struct block_device *dev,
+static int mtip_block_getgeo(struct gendisk *disk,
                                struct hd_geometry *geo)
 {
-       struct driver_data *dd = dev->bd_disk->private_data;
+       struct driver_data *dd = disk->private_data;
        sector_t capacity;
 
        if (!dd)
index 15627417f12e089bd3d7c87b8a2a7714fd90f3f0..119b7e27023f96ca62dc47d730b5b585a01235cd 100644 (file)
@@ -942,11 +942,11 @@ static void rnbd_client_release(struct gendisk *gen)
        rnbd_clt_put_dev(dev);
 }
 
-static int rnbd_client_getgeo(struct block_device *block_device,
+static int rnbd_client_getgeo(struct gendisk *disk,
                              struct hd_geometry *geo)
 {
        u64 size;
-       struct rnbd_clt_dev *dev = block_device->bd_disk->private_data;
+       struct rnbd_clt_dev *dev = disk->private_data;
        struct queue_limits *limit = &dev->queue->limits;
 
        size = dev->size * (limit->logical_block_size / SECTOR_SIZE);
index 7af21fe6767172029c28ae1a1f0d296b3e2278c3..107751721178d7109371615232ba4c8f5b5db054 100644 (file)
@@ -119,9 +119,8 @@ static inline u32 vdc_tx_dring_avail(struct vio_dring_state *dr)
        return vio_dring_avail(dr, VDC_TX_RING_SIZE);
 }
 
-static int vdc_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int vdc_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct gendisk *disk = bdev->bd_disk;
        sector_t nsect = get_capacity(disk);
        sector_t cylinders = nsect;
 
index eda33c5eb5e2951d0d48527d03e3899476b70059..416015947ae63a90cf6dca82bd85b431fdea6d9a 100644 (file)
@@ -711,9 +711,9 @@ static int floppy_ioctl(struct block_device *bdev, blk_mode_t mode,
        return -ENOTTY;
 }
 
-static int floppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int floppy_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct floppy_state *fs = bdev->bd_disk->private_data;
+       struct floppy_state *fs = disk->private_data;
        struct floppy_struct *g;
        int ret;
 
index e649fa67bac16b4f0c6e8e8f0e6bec111897c355..85efa7e535f8ba4db358ed74cc9a71aff4631639 100644 (file)
@@ -829,9 +829,9 @@ out:
 }
 
 /* We provide getgeo only to please some old bootloader/partitioning tools */
-static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
+static int virtblk_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct virtio_blk *vblk = bd->bd_disk->private_data;
+       struct virtio_blk *vblk = disk->private_data;
        int ret = 0;
 
        mutex_lock(&vblk->vdev_mutex);
@@ -853,7 +853,7 @@ static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
                /* some standard values, similar to sd */
                geo->heads = 1 << 6;
                geo->sectors = 1 << 5;
-               geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+               geo->cylinders = get_capacity(disk) >> 11;
        }
 out:
        mutex_unlock(&vblk->vdev_mutex);
index 5babe575c28831745dd3d5feeca20f8dce4c270d..04fc6b552c049844d035ed607dd00d0d8d3941af 100644 (file)
@@ -493,11 +493,11 @@ static void blkif_restart_queue_callback(void *arg)
        schedule_work(&rinfo->work);
 }
 
-static int blkif_getgeo(struct block_device *bd, struct hd_geometry *hg)
+static int blkif_getgeo(struct gendisk *disk, struct hd_geometry *hg)
 {
        /* We don't have real geometry info, but let's at least return
           values consistent with the size of the device */
-       sector_t nsect = get_capacity(bd->bd_disk);
+       sector_t nsect = get_capacity(disk);
        sector_t cylinders = nsect;
 
        hg->heads = 0xff;
index a44e8c2dccee4ed2a41614d037e824afc79762e4..7bd6fa05b00a39515ed4ec7b522b3cc446cf797c 100644 (file)
@@ -403,9 +403,9 @@ static void do_deferred_remove(struct work_struct *w)
        dm_deferred_remove();
 }
 
-static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int dm_blk_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct mapped_device *md = bdev->bd_disk->private_data;
+       struct mapped_device *md = disk->private_data;
 
        return dm_get_geometry(md, geo);
 }
index ac85ec73a409e733b1029561bd19407f30c34433..236bb04f3e54823a5c7d52a6aa870d85662cedb9 100644 (file)
@@ -7678,9 +7678,9 @@ static int set_disk_faulty(struct mddev *mddev, dev_t dev)
  * 4 sectors (with a BIG number of cylinders...). This drives
  * dosfs just mad... ;-)
  */
-static int md_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int md_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct mddev *mddev = bdev->bd_disk->private_data;
+       struct mddev *mddev = disk->private_data;
 
        geo->heads = 2;
        geo->sectors = 4;
index d34892782f6e47e1a8bde3d5e77a3fbc4101078d..1af157ce0a637762bd18bcc0bd5a00a02e694783 100644 (file)
@@ -1953,10 +1953,10 @@ static void msb_data_clear(struct msb_data *msb)
        msb->card = NULL;
 }
 
-static int msb_bd_getgeo(struct block_device *bdev,
+static int msb_bd_getgeo(struct gendisk *disk,
                                 struct hd_geometry *geo)
 {
-       struct msb_data *msb = bdev->bd_disk->private_data;
+       struct msb_data *msb = disk->private_data;
        *geo = msb->geometry;
        return 0;
 }
index c9853d887d2822632b9d76da0cb101dfc3598a74..075519caa5473e794cdf8ac56db06b24360466d7 100644 (file)
@@ -189,10 +189,10 @@ static void mspro_block_bd_free_disk(struct gendisk *disk)
        kfree(msb);
 }
 
-static int mspro_block_bd_getgeo(struct block_device *bdev,
+static int mspro_block_bd_getgeo(struct gendisk *disk,
                                 struct hd_geometry *geo)
 {
-       struct mspro_block_data *msb = bdev->bd_disk->private_data;
+       struct mspro_block_data *msb = disk->private_data;
 
        geo->heads = msb->heads;
        geo->sectors = msb->sectors_per_track;
index 9cc47bf94804b64a9cc60c7a5d95a0082d546ea9..d1f295af97135e75af365a33a2930f570b39ff52 100644 (file)
@@ -435,9 +435,9 @@ static void mmc_blk_release(struct gendisk *disk)
 }
 
 static int
-mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+mmc_blk_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       geo->cylinders = get_capacity(bdev->bd_disk) / (4 * 16);
+       geo->cylinders = get_capacity(disk) / (4 * 16);
        geo->heads = 4;
        geo->sectors = 16;
        return 0;
index 847c11542f024c3d1333c24fb8ea9f3479506be0..28e09d08044059fa857317bef607c570b6ce79a2 100644 (file)
@@ -246,9 +246,9 @@ unlock:
        blktrans_dev_put(dev);
 }
 
-static int blktrans_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int blktrans_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct mtd_blktrans_dev *dev = bdev->bd_disk->private_data;
+       struct mtd_blktrans_dev *dev = disk->private_data;
        int ret = -ENXIO;
 
        mutex_lock(&dev->lock);
index 39cc0a6a4d3771741741ab7374f834b80d094c84..b53fd147fa650ba4c5d8551a55a8411c1aa034e6 100644 (file)
@@ -282,12 +282,12 @@ static void ubiblock_release(struct gendisk *gd)
        mutex_unlock(&dev->dev_mutex);
 }
 
-static int ubiblock_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int ubiblock_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
        /* Some tools might require this information */
        geo->heads = 1;
        geo->cylinders = 1;
-       geo->sectors = get_capacity(bdev->bd_disk);
+       geo->sectors = get_capacity(disk);
        geo->start = 0;
        return 0;
 }
index 2a1aa32e66938380867665612aa6a35f008cae54..a933db961ed701df2c30aa106676587e021b9a93 100644 (file)
@@ -1478,12 +1478,12 @@ static void btt_submit_bio(struct bio *bio)
        bio_endio(bio);
 }
 
-static int btt_getgeo(struct block_device *bd, struct hd_geometry *geo)
+static int btt_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
        /* some standard values */
        geo->heads = 1 << 6;
        geo->sectors = 1 << 5;
-       geo->cylinders = get_capacity(bd->bd_disk) >> 11;
+       geo->cylinders = get_capacity(disk) >> 11;
        return 0;
 }
 
index 812c1565114fde21000c80ae8968c4346179133d..f96f74bff6adb31eb40a864afd57e5e494dcfbb8 100644 (file)
@@ -1803,12 +1803,12 @@ static void nvme_release(struct gendisk *disk)
        nvme_ns_release(disk->private_data);
 }
 
-int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+int nvme_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
        /* some standard values */
        geo->heads = 1 << 6;
        geo->sectors = 1 << 5;
-       geo->cylinders = get_capacity(bdev->bd_disk) >> 11;
+       geo->cylinders = get_capacity(disk) >> 11;
        return 0;
 }
 
index cfd2b5b90b915728e0c56e8b7c9971b771806c43..102fae6a231c57598f4312717fd9d38cc24501ba 100644 (file)
@@ -936,7 +936,7 @@ int nvme_ns_head_chr_uring_cmd(struct io_uring_cmd *ioucmd,
                unsigned int issue_flags);
 int nvme_identify_ns(struct nvme_ctrl *ctrl, unsigned nsid,
                struct nvme_id_ns **id);
-int nvme_getgeo(struct block_device *bdev, struct hd_geometry *geo);
+int nvme_getgeo(struct gendisk *disk, struct hd_geometry *geo);
 int nvme_dev_uring_cmd(struct io_uring_cmd *ioucmd, unsigned int issue_flags);
 
 extern const struct attribute_group *nvme_ns_attr_groups[];
index 506a947d00a51bb7acf855ee02c1a261c9730bf2..582ac7e61b240d76834e4e57701d9eed2048d862 100644 (file)
@@ -3317,11 +3317,11 @@ static void dasd_release(struct gendisk *disk)
 /*
  * Return disk geometry.
  */
-static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int dasd_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
        struct dasd_device *base;
 
-       base = dasd_device_from_gendisk(bdev->bd_disk);
+       base = dasd_device_from_gendisk(disk);
        if (!base)
                return -ENODEV;
 
@@ -3331,7 +3331,8 @@ static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
                return -EINVAL;
        }
        base->discipline->fill_geometry(base->block, geo);
-       geo->start = get_start_sect(bdev) >> base->block->s2b_shift;
+       // geo->start is left unchanged by the above
+       geo->start >>= base->block->s2b_shift;
        dasd_put_device(base);
        return 0;
 }
index 3edcc43f180bc2ff61681cf156869a6284e9cb99..00ad574ce61c5c453226f17e677b3b25aa1c9727 100644 (file)
@@ -1599,9 +1599,9 @@ static void sd_release(struct gendisk *disk)
        scsi_device_put(sdev);
 }
 
-static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+static int sd_getgeo(struct gendisk *disk, struct hd_geometry *geo)
 {
-       struct scsi_disk *sdkp = scsi_disk(bdev->bd_disk);
+       struct scsi_disk *sdkp = scsi_disk(disk);
        struct scsi_device *sdp = sdkp->device;
        struct Scsi_Host *host = sdp->host;
        sector_t capacity = logical_to_sectors(sdp, sdkp->capacity);
@@ -1614,9 +1614,9 @@ static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 
        /* override with calculated, extended default, or driver values */
        if (host->hostt->bios_param)
-               host->hostt->bios_param(sdp, bdev->bd_disk, capacity, diskinfo);
+               host->hostt->bios_param(sdp, disk, capacity, diskinfo);
        else
-               scsicam_bios_param(bdev->bd_disk, capacity, diskinfo);
+               scsicam_bios_param(disk, capacity, diskinfo);
 
        geo->heads = diskinfo[0];
        geo->sectors = diskinfo[1];
index 95886b404b16b70dbbf95b6085df3ce0c2cb428c..fbc45121cd4fd083109acf3e573a9bd33257ef36 100644 (file)
@@ -1659,7 +1659,7 @@ struct block_device_operations {
        unsigned int (*check_events) (struct gendisk *disk,
                                      unsigned int clearing);
        void (*unlock_native_capacity) (struct gendisk *);
-       int (*getgeo)(struct block_device *, struct hd_geometry *);
+       int (*getgeo)(struct gendisk *, struct hd_geometry *);
        int (*set_read_only)(struct block_device *bdev, bool ro);
        void (*free_disk)(struct gendisk *disk);
        /* this callback is with swap_lock and sometimes page table lock held */