block: genhd: add 'groups' argument to device_add_disk
authorHannes Reinecke <hare@suse.de>
Fri, 28 Sep 2018 06:17:19 +0000 (08:17 +0200)
committerJens Axboe <axboe@kernel.dk>
Fri, 28 Sep 2018 14:30:28 +0000 (08:30 -0600)
Update device_add_disk() to take an 'groups' argument so that
individual drivers can register a device with additional sysfs
attributes.
This avoids race condition the driver would otherwise have if these
groups were to be created with sysfs_add_groups().

Signed-off-by: Martin Wilck <martin.wilck@suse.com>
Signed-off-by: Hannes Reinecke <hare@suse.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
28 files changed:
arch/um/drivers/ubd_kern.c
block/genhd.c
drivers/block/floppy.c
drivers/block/mtip32xx/mtip32xx.c
drivers/block/ps3disk.c
drivers/block/ps3vram.c
drivers/block/rsxx/dev.c
drivers/block/skd_main.c
drivers/block/sunvdc.c
drivers/block/virtio_blk.c
drivers/block/xen-blkfront.c
drivers/ide/ide-cd.c
drivers/ide/ide-gd.c
drivers/memstick/core/ms_block.c
drivers/memstick/core/mspro_block.c
drivers/mmc/core/block.c
drivers/mtd/mtd_blkdevs.c
drivers/nvdimm/blk.c
drivers/nvdimm/btt.c
drivers/nvdimm/pmem.c
drivers/nvme/host/core.c
drivers/nvme/host/multipath.c
drivers/s390/block/dasd_genhd.c
drivers/s390/block/dcssblk.c
drivers/s390/block/scm_blk.c
drivers/scsi/sd.c
drivers/scsi/sr.c
include/linux/genhd.h

index 83c470364dfb34dce51320322e9b119c10157f3e..6ee4c56032f78722d2c3fc46dc12d69ed4b14d9f 100644 (file)
@@ -891,7 +891,7 @@ static int ubd_disk_register(int major, u64 size, int unit,
 
        disk->private_data = &ubd_devs[unit];
        disk->queue = ubd_devs[unit].queue;
-       device_add_disk(parent, disk);
+       device_add_disk(parent, disk, NULL);
 
        *disk_out = disk;
        return 0;
index 8cc719a37b32f0500f081b46e12b91635204e9da..ef0936184d6983ed7ab968ec0ab5bdb176ea53da 100644 (file)
@@ -567,7 +567,8 @@ static int exact_lock(dev_t devt, void *data)
        return 0;
 }
 
-static void register_disk(struct device *parent, struct gendisk *disk)
+static void register_disk(struct device *parent, struct gendisk *disk,
+                         const struct attribute_group **groups)
 {
        struct device *ddev = disk_to_dev(disk);
        struct block_device *bdev;
@@ -582,6 +583,10 @@ static void register_disk(struct device *parent, struct gendisk *disk)
        /* delay uevents, until we scanned partition table */
        dev_set_uevent_suppress(ddev, 1);
 
+       if (groups) {
+               WARN_ON(ddev->groups);
+               ddev->groups = groups;
+       }
        if (device_add(ddev))
                return;
        if (!sysfs_deprecated) {
@@ -647,6 +652,7 @@ exit:
  * __device_add_disk - add disk information to kernel list
  * @parent: parent device for the disk
  * @disk: per-device partitioning information
+ * @groups: Additional per-device sysfs groups
  * @register_queue: register the queue if set to true
  *
  * This function registers the partitioning information in @disk
@@ -655,6 +661,7 @@ exit:
  * FIXME: error handling
  */
 static void __device_add_disk(struct device *parent, struct gendisk *disk,
+                             const struct attribute_group **groups,
                              bool register_queue)
 {
        dev_t devt;
@@ -698,7 +705,7 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
                blk_register_region(disk_devt(disk), disk->minors, NULL,
                                    exact_match, exact_lock, disk);
        }
-       register_disk(parent, disk);
+       register_disk(parent, disk, groups);
        if (register_queue)
                blk_register_queue(disk);
 
@@ -712,15 +719,17 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
        blk_integrity_add(disk);
 }
 
-void device_add_disk(struct device *parent, struct gendisk *disk)
+void device_add_disk(struct device *parent, struct gendisk *disk,
+                    const struct attribute_group **groups)
+
 {
-       __device_add_disk(parent, disk, true);
+       __device_add_disk(parent, disk, groups, true);
 }
 EXPORT_SYMBOL(device_add_disk);
 
 void device_add_disk_no_queue_reg(struct device *parent, struct gendisk *disk)
 {
-       __device_add_disk(parent, disk, false);
+       __device_add_disk(parent, disk, NULL, false);
 }
 EXPORT_SYMBOL(device_add_disk_no_queue_reg);
 
index 48f622728ce6a1a6006109b711b6d9077ce56cdf..1bc99e9dfaee9e09aed69fd487df82d8756a8d60 100644 (file)
@@ -4676,7 +4676,7 @@ static int __init do_floppy_init(void)
                /* to be cleaned up... */
                disks[drive]->private_data = (void *)(long)drive;
                disks[drive]->flags |= GENHD_FL_REMOVABLE;
-               device_add_disk(&floppy_device[drive].dev, disks[drive]);
+               device_add_disk(&floppy_device[drive].dev, disks[drive], NULL);
        }
 
        return 0;
index d0666f5ce0036aea97404cdfd76a515b5bd49da2..1d7d48d8a20506d795f194dd0d2cd7cb248da648 100644 (file)
@@ -3861,7 +3861,7 @@ skip_create_disk:
        set_capacity(dd->disk, capacity);
 
        /* Enable the block device and add it to /dev */
-       device_add_disk(&dd->pdev->dev, dd->disk);
+       device_add_disk(&dd->pdev->dev, dd->disk, NULL);
 
        dd->bdev = bdget_disk(dd->disk, 0);
        /*
index afe1508d82c6daba89b404414398406850391571..29a4419e8ba3e93feff187f86b381ef37f6a2ac4 100644 (file)
@@ -500,7 +500,7 @@ static int ps3disk_probe(struct ps3_system_bus_device *_dev)
                 gendisk->disk_name, priv->model, priv->raw_capacity >> 11,
                 get_capacity(gendisk) >> 11);
 
-       device_add_disk(&dev->sbd.core, gendisk);
+       device_add_disk(&dev->sbd.core, gendisk, NULL);
        return 0;
 
 fail_cleanup_queue:
index 1e3d5de9d8387e16ed0735711328314380ca8873..c0c50816a10bb6efc8ddd254e9661dd100eaaf88 100644 (file)
@@ -769,7 +769,7 @@ static int ps3vram_probe(struct ps3_system_bus_device *dev)
        dev_info(&dev->core, "%s: Using %lu MiB of GPU memory\n",
                 gendisk->disk_name, get_capacity(gendisk) >> 11);
 
-       device_add_disk(&dev->core, gendisk);
+       device_add_disk(&dev->core, gendisk, NULL);
        return 0;
 
 fail_cleanup_queue:
index 1a92f9e6593746c41db8f9b4e1a893840573d4a9..3894aa0f350b7683c9bfed43595f7bd34ff78bd9 100644 (file)
@@ -226,7 +226,7 @@ int rsxx_attach_dev(struct rsxx_cardinfo *card)
                        set_capacity(card->gendisk, card->size8 >> 9);
                else
                        set_capacity(card->gendisk, 0);
-               device_add_disk(CARD_TO_DEV(card), card->gendisk);
+               device_add_disk(CARD_TO_DEV(card), card->gendisk, NULL);
                card->bdev_attached = 1;
        }
 
index 87b9e7fbf0621af826e2b67cc9e518a60a5c6724..a85c9a622c41bf5c03539d6f828b0a4cb852c948 100644 (file)
@@ -3104,7 +3104,7 @@ static int skd_bdev_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 static int skd_bdev_attach(struct device *parent, struct skd_device *skdev)
 {
        dev_dbg(&skdev->pdev->dev, "add_disk\n");
-       device_add_disk(parent, skdev->disk);
+       device_add_disk(parent, skdev->disk, NULL);
        return 0;
 }
 
index 5ca56bfae63cf69872cd18270fb8c980db4eddae..09409edce384d8a0e4d83d0158281738d5171f88 100644 (file)
@@ -850,7 +850,7 @@ static int probe_disk(struct vdc_port *port)
               port->vdisk_size, (port->vdisk_size >> (20 - 9)),
               port->vio.ver.major, port->vio.ver.minor);
 
-       device_add_disk(&port->vio.vdev->dev, g);
+       device_add_disk(&port->vio.vdev->dev, g, NULL);
 
        return 0;
 }
index 23752dc99b008c4b2075ee03860627b729ea54ba..fe80560000a1bc5f0c9506523887a604be5489bd 100644 (file)
@@ -780,7 +780,7 @@ static int virtblk_probe(struct virtio_device *vdev)
        virtblk_update_capacity(vblk, false);
        virtio_device_ready(vdev);
 
-       device_add_disk(&vdev->dev, vblk->disk);
+       device_add_disk(&vdev->dev, vblk->disk, NULL);
        err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial);
        if (err)
                goto out_del_disk;
index a71d817e900ddc07ff45d240f0ae290ff408b6cd..e5e40272d233decd837a219c2dd5b8434d4d84e1 100644 (file)
@@ -2420,7 +2420,7 @@ static void blkfront_connect(struct blkfront_info *info)
        for (i = 0; i < info->nr_rings; i++)
                kick_pending_request_queues(&info->rinfo[i]);
 
-       device_add_disk(&info->xbdev->dev, info->gd);
+       device_add_disk(&info->xbdev->dev, info->gd, NULL);
 
        info->is_ready = 1;
        return;
index 44a7a255ef74a5b43527c3e9ec7f9fa047838f92..f9b59d41813f96694cdc425070959afa3b2542bd 100644 (file)
@@ -1784,7 +1784,7 @@ static int ide_cd_probe(ide_drive_t *drive)
        ide_cd_read_toc(drive);
        g->fops = &idecd_ops;
        g->flags |= GENHD_FL_REMOVABLE | GENHD_FL_BLOCK_EVENTS_ON_EXCL_WRITE;
-       device_add_disk(&drive->gendev, g);
+       device_add_disk(&drive->gendev, g, NULL);
        return 0;
 
 out_free_disk:
index e823394ed543470e98114a8a33e3ceb9ab084b24..04e008e8f6f9db63776160fc2dbd928d6af33fed 100644 (file)
@@ -416,7 +416,7 @@ static int ide_gd_probe(ide_drive_t *drive)
        if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
                g->flags = GENHD_FL_REMOVABLE;
        g->fops = &ide_gd_ops;
-       device_add_disk(&drive->gendev, g);
+       device_add_disk(&drive->gendev, g, NULL);
        return 0;
 
 out_free_disk:
index 716fc8ed31d324dc4daa8ad83d730217ae5457f0..8a02f11076f9a3b0d0a1129c0d08a0f817bb112d 100644 (file)
@@ -2146,7 +2146,7 @@ static int msb_init_disk(struct memstick_dev *card)
                set_disk_ro(msb->disk, 1);
 
        msb_start(card);
-       device_add_disk(&card->dev, msb->disk);
+       device_add_disk(&card->dev, msb->disk, NULL);
        dbg("Disk added");
        return 0;
 
index 5ee932631faed7230edfcdd33f6e13b9be25b115..0cd30dcb68017f7acdf64dee3a492be11c8d70e4 100644 (file)
@@ -1236,7 +1236,7 @@ static int mspro_block_init_disk(struct memstick_dev *card)
        set_capacity(msb->disk, capacity);
        dev_dbg(&card->dev, "capacity set %ld\n", capacity);
 
-       device_add_disk(&card->dev, msb->disk);
+       device_add_disk(&card->dev, msb->disk, NULL);
        msb->active = 1;
        return 0;
 
index a0b9102c4c6e10dca0472328e7f97631863a9208..de8e1a8be690a0faaceb9adda96b455b48cdd837 100644 (file)
@@ -2698,7 +2698,7 @@ static int mmc_add_disk(struct mmc_blk_data *md)
        int ret;
        struct mmc_card *card = md->queue.card;
 
-       device_add_disk(md->parent, md->disk);
+       device_add_disk(md->parent, md->disk, NULL);
        md->force_ro.show = force_ro_show;
        md->force_ro.store = force_ro_store;
        sysfs_attr_init(&md->force_ro.attr);
index 29c0bfd74e8a19e1ce37d97033d40e959a8b5348..6a41dfa3c36baa4ce2c4806bbe66c49f42ce5881 100644 (file)
@@ -447,7 +447,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
        if (new->readonly)
                set_disk_ro(gd, 1);
 
-       device_add_disk(&new->mtd->dev, gd);
+       device_add_disk(&new->mtd->dev, gd, NULL);
 
        if (new->disk_attributes) {
                ret = sysfs_create_group(&disk_to_dev(gd)->kobj,
index 62e9cb167aad520228bc55a97348ab75b07ddd36..db45c6bbb7bb13da8f6b8a06ed6a4af55ef22778 100644 (file)
@@ -290,7 +290,7 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk)
        }
 
        set_capacity(disk, available_disk_size >> SECTOR_SHIFT);
-       device_add_disk(dev, disk);
+       device_add_disk(dev, disk, NULL);
        revalidate_disk(disk);
        return 0;
 }
index 0360c015f6580b1cb5fef2667b2844381f0c8696..b123b0dcf27477b02289d76dfbf88585943e3ca2 100644 (file)
@@ -1556,7 +1556,7 @@ static int btt_blk_init(struct btt *btt)
                }
        }
        set_capacity(btt->btt_disk, btt->nlba * btt->sector_size >> 9);
-       device_add_disk(&btt->nd_btt->dev, btt->btt_disk);
+       device_add_disk(&btt->nd_btt->dev, btt->btt_disk, NULL);
        btt->nd_btt->size = btt->nlba * (u64)btt->sector_size;
        revalidate_disk(btt->btt_disk);
 
index 6071e2942053c903564d6f08f278d3735a619308..a75d10c23d80d2dcd76008a45665bb6853690adc 100644 (file)
@@ -474,7 +474,7 @@ static int pmem_attach_disk(struct device *dev,
        gendev = disk_to_dev(disk);
        gendev->groups = pmem_attribute_groups;
 
-       device_add_disk(dev, disk);
+       device_add_disk(dev, disk, NULL);
        if (devm_add_action_or_reset(dev, pmem_release_disk, pmem))
                return -ENOMEM;
 
index dd8ec1dd92190997f823e0bfb72389baea73b268..0e824e8c8fd78ab196f53efbc3a10fec079308ca 100644 (file)
@@ -3099,7 +3099,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
 
        nvme_get_ctrl(ctrl);
 
-       device_add_disk(ctrl->device, ns->disk);
+       device_add_disk(ctrl->device, ns->disk, NULL);
        if (sysfs_create_group(&disk_to_dev(ns->disk)->kobj,
                                        &nvme_ns_id_attr_group))
                pr_warn("%s: failed to create sysfs group for identification\n",
index 5a9562881d4ef87ddfbd749555f1c8eccf01acc5..477af51d01e86abe336b5ba34f82b1c612ad46c8 100644 (file)
@@ -283,7 +283,7 @@ static void nvme_mpath_set_live(struct nvme_ns *ns)
                return;
 
        if (!(head->disk->flags & GENHD_FL_UP)) {
-               device_add_disk(&head->subsys->dev, head->disk);
+               device_add_disk(&head->subsys->dev, head->disk, NULL);
                if (sysfs_create_group(&disk_to_dev(head->disk)->kobj,
                                &nvme_ns_id_attr_group))
                        dev_warn(&head->subsys->dev,
index 7036a6c6f86ff934ccdff648bb365c532befd4ee..5542d9eadfe0e3b6ccd7f053e8ee0f3dc51a5b11 100644 (file)
@@ -76,7 +76,7 @@ int dasd_gendisk_alloc(struct dasd_block *block)
        gdp->queue = block->request_queue;
        block->gdp = gdp;
        set_capacity(block->gdp, 0);
-       device_add_disk(&base->cdev->dev, block->gdp);
+       device_add_disk(&base->cdev->dev, block->gdp, NULL);
        return 0;
 }
 
index 23e526cda5c10b7e61a059a63c3c83f8ed0dc0d8..4e8aedd50cb0d6ecf55f67d1071a8b39004f5c9a 100644 (file)
@@ -685,7 +685,7 @@ dcssblk_add_store(struct device *dev, struct device_attribute *attr, const char
        }
 
        get_device(&dev_info->dev);
-       device_add_disk(&dev_info->dev, dev_info->gd);
+       device_add_disk(&dev_info->dev, dev_info->gd, NULL);
 
        switch (dev_info->segment_type) {
                case SEG_TYPE_SR:
index 98f66b7b6794512f6a761bfd2cd13f9a1faacfbf..e01889394c8412654eab27e8386f00b28e2383a8 100644 (file)
@@ -500,7 +500,7 @@ int scm_blk_dev_setup(struct scm_blk_dev *bdev, struct scm_device *scmdev)
 
        /* 512 byte sectors */
        set_capacity(bdev->gendisk, scmdev->size >> 9);
-       device_add_disk(&scmdev->dev, bdev->gendisk);
+       device_add_disk(&scmdev->dev, bdev->gendisk, NULL);
        return 0;
 
 out_queue:
index 64514e8359e4c0928401b41576f29f08452323d7..67ed5906b462ec95be52f795b86271d7742a6e20 100644 (file)
@@ -3272,7 +3272,7 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
        }
 
        blk_pm_runtime_init(sdp->request_queue, dev);
-       device_add_disk(dev, gd);
+       device_add_disk(dev, gd, NULL);
        if (sdkp->capacity)
                sd_dif_config_host(sdkp);
 
index 4f07b3410595074255ffa518b0e8c542db596b27..54dd70ae9731d72f0c07a350c57d313351581e45 100644 (file)
@@ -759,7 +759,7 @@ static int sr_probe(struct device *dev)
 
        dev_set_drvdata(dev, cd);
        disk->flags |= GENHD_FL_REMOVABLE;
-       device_add_disk(&sdev->sdev_gendev, disk);
+       device_add_disk(&sdev->sdev_gendev, disk, NULL);
 
        sdev_printk(KERN_DEBUG, sdev,
                    "Attached scsi CD-ROM %s\n", cd->cdi.name);
index 57864422a2c8813b9f6ddd902a3c6b8794c2f4ee..0b820ff058393760767b7406a7d19296ead2dfce 100644 (file)
@@ -399,10 +399,11 @@ static inline void free_part_info(struct hd_struct *part)
 extern void part_round_stats(struct request_queue *q, int cpu, struct hd_struct *part);
 
 /* block/genhd.c */
-extern void device_add_disk(struct device *parent, struct gendisk *disk);
+extern void device_add_disk(struct device *parent, struct gendisk *disk,
+                           const struct attribute_group **groups);
 static inline void add_disk(struct gendisk *disk)
 {
-       device_add_disk(NULL, disk);
+       device_add_disk(NULL, disk, NULL);
 }
 extern void device_add_disk_no_queue_reg(struct device *parent, struct gendisk *disk);
 static inline void add_disk_no_queue_reg(struct gendisk *disk)