Commit a711d91c authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: add a cdrom_device_info pointer to struct gendisk

Add a pointer to the CDROM information structure to struct gendisk.
This will allow various removable media file systems to call directly
into the CDROM layer instead of abusing ioctls with kernel pointers.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 21f3cfea
...@@ -1032,7 +1032,7 @@ static int __init pcd_init(void) ...@@ -1032,7 +1032,7 @@ static int __init pcd_init(void)
for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) { for (unit = 0, cd = pcd; unit < PCD_UNITS; unit++, cd++) {
if (cd->present) { if (cd->present) {
register_cdrom(&cd->info); register_cdrom(cd->disk, &cd->info);
cd->disk->private_data = cd; cd->disk->private_data = cd;
add_disk(cd->disk); add_disk(cd->disk);
} }
......
...@@ -586,7 +586,7 @@ static int cdrom_mrw_set_lba_space(struct cdrom_device_info *cdi, int space) ...@@ -586,7 +586,7 @@ static int cdrom_mrw_set_lba_space(struct cdrom_device_info *cdi, int space)
return 0; return 0;
} }
int register_cdrom(struct cdrom_device_info *cdi) int register_cdrom(struct gendisk *disk, struct cdrom_device_info *cdi)
{ {
static char banner_printed; static char banner_printed;
const struct cdrom_device_ops *cdo = cdi->ops; const struct cdrom_device_ops *cdo = cdi->ops;
...@@ -601,6 +601,9 @@ int register_cdrom(struct cdrom_device_info *cdi) ...@@ -601,6 +601,9 @@ int register_cdrom(struct cdrom_device_info *cdi)
cdrom_sysctl_register(); cdrom_sysctl_register();
} }
cdi->disk = disk;
disk->cdi = cdi;
ENSURE(cdo, drive_status, CDC_DRIVE_STATUS); ENSURE(cdo, drive_status, CDC_DRIVE_STATUS);
if (cdo->check_events == NULL && cdo->media_changed == NULL) if (cdo->check_events == NULL && cdo->media_changed == NULL)
WARN_ON_ONCE(cdo->capability & (CDC_MEDIA_CHANGED | CDC_SELECT_DISC)); WARN_ON_ONCE(cdo->capability & (CDC_MEDIA_CHANGED | CDC_SELECT_DISC));
......
...@@ -770,7 +770,7 @@ static int probe_gdrom(struct platform_device *devptr) ...@@ -770,7 +770,7 @@ static int probe_gdrom(struct platform_device *devptr)
goto probe_fail_no_disk; goto probe_fail_no_disk;
} }
probe_gdrom_setupdisk(); probe_gdrom_setupdisk();
if (register_cdrom(gd.cd_info)) { if (register_cdrom(gd.disk, gd.cd_info)) {
err = -ENODEV; err = -ENODEV;
goto probe_fail_cdrom_register; goto probe_fail_cdrom_register;
} }
......
...@@ -1305,8 +1305,7 @@ static int ide_cdrom_register(ide_drive_t *drive, int nslots) ...@@ -1305,8 +1305,7 @@ static int ide_cdrom_register(ide_drive_t *drive, int nslots)
if (drive->atapi_flags & IDE_AFLAG_NO_SPEED_SELECT) if (drive->atapi_flags & IDE_AFLAG_NO_SPEED_SELECT)
devinfo->mask |= CDC_SELECT_SPEED; devinfo->mask |= CDC_SELECT_SPEED;
devinfo->disk = info->disk; return register_cdrom(info->disk, devinfo);
return register_cdrom(devinfo);
} }
static int ide_cdrom_probe_capabilities(ide_drive_t *drive) static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
......
...@@ -794,9 +794,8 @@ static int sr_probe(struct device *dev) ...@@ -794,9 +794,8 @@ static int sr_probe(struct device *dev)
set_capacity(disk, cd->capacity); set_capacity(disk, cd->capacity);
disk->private_data = &cd->driver; disk->private_data = &cd->driver;
disk->queue = sdev->request_queue; disk->queue = sdev->request_queue;
cd->cdi.disk = disk;
if (register_cdrom(&cd->cdi)) if (register_cdrom(disk, &cd->cdi))
goto fail_put; goto fail_put;
/* /*
......
...@@ -104,7 +104,7 @@ extern unsigned int cdrom_check_events(struct cdrom_device_info *cdi, ...@@ -104,7 +104,7 @@ extern unsigned int cdrom_check_events(struct cdrom_device_info *cdi,
unsigned int clearing); unsigned int clearing);
extern int cdrom_media_changed(struct cdrom_device_info *); extern int cdrom_media_changed(struct cdrom_device_info *);
extern int register_cdrom(struct cdrom_device_info *cdi); extern int register_cdrom(struct gendisk *disk, struct cdrom_device_info *cdi);
extern void unregister_cdrom(struct cdrom_device_info *cdi); extern void unregister_cdrom(struct cdrom_device_info *cdi);
typedef struct { typedef struct {
......
...@@ -217,11 +217,20 @@ struct gendisk { ...@@ -217,11 +217,20 @@ struct gendisk {
#ifdef CONFIG_BLK_DEV_INTEGRITY #ifdef CONFIG_BLK_DEV_INTEGRITY
struct kobject integrity_kobj; struct kobject integrity_kobj;
#endif /* CONFIG_BLK_DEV_INTEGRITY */ #endif /* CONFIG_BLK_DEV_INTEGRITY */
#if IS_ENABLED(CONFIG_CDROM)
struct cdrom_device_info *cdi;
#endif
int node_id; int node_id;
struct badblocks *bb; struct badblocks *bb;
struct lockdep_map lockdep_map; struct lockdep_map lockdep_map;
}; };
#if IS_REACHABLE(CONFIG_CDROM)
#define disk_to_cdi(disk) ((disk)->cdi)
#else
#define disk_to_cdi(disk) NULL
#endif
static inline struct gendisk *part_to_disk(struct hd_struct *part) static inline struct gendisk *part_to_disk(struct hd_struct *part)
{ {
if (likely(part)) { if (likely(part)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment