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

scsi: don't use disk->private_data to find the scsi_driver

Requiring every ULP to have the scsi_drive as first member of the
private data is rather fragile and not necessary anyway.  Just use
the driver hanging off the SCSI device instead.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Reviewed-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: default avatarMing Lei <ming.lei@redhat.com>
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Link: https://lore.kernel.org/r/20220308055200.735835-4-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent e02657ea
...@@ -3515,7 +3515,6 @@ static int sd_probe(struct device *dev) ...@@ -3515,7 +3515,6 @@ static int sd_probe(struct device *dev)
} }
sdkp->device = sdp; sdkp->device = sdp;
sdkp->driver = &sd_template;
sdkp->disk = gd; sdkp->disk = gd;
sdkp->index = index; sdkp->index = index;
sdkp->max_retries = SD_MAX_RETRIES; sdkp->max_retries = SD_MAX_RETRIES;
...@@ -3548,7 +3547,7 @@ static int sd_probe(struct device *dev) ...@@ -3548,7 +3547,7 @@ static int sd_probe(struct device *dev)
gd->minors = SD_MINORS; gd->minors = SD_MINORS;
gd->fops = &sd_fops; gd->fops = &sd_fops;
gd->private_data = &sdkp->driver; gd->private_data = sdkp;
/* defaults, until the device tells us otherwise */ /* defaults, until the device tells us otherwise */
sdp->sector_size = 512; sdp->sector_size = 512;
......
...@@ -68,7 +68,6 @@ enum { ...@@ -68,7 +68,6 @@ enum {
}; };
struct scsi_disk { struct scsi_disk {
struct scsi_driver *driver; /* always &sd_template */
struct scsi_device *device; struct scsi_device *device;
struct device dev; struct device dev;
struct gendisk *disk; struct gendisk *disk;
...@@ -131,7 +130,7 @@ struct scsi_disk { ...@@ -131,7 +130,7 @@ struct scsi_disk {
static inline struct scsi_disk *scsi_disk(struct gendisk *disk) static inline struct scsi_disk *scsi_disk(struct gendisk *disk)
{ {
return container_of(disk->private_data, struct scsi_disk, driver); return disk->private_data;
} }
#define sd_printk(prefix, sdsk, fmt, a...) \ #define sd_printk(prefix, sdsk, fmt, a...) \
......
...@@ -147,7 +147,7 @@ static void sr_kref_release(struct kref *kref); ...@@ -147,7 +147,7 @@ static void sr_kref_release(struct kref *kref);
static inline struct scsi_cd *scsi_cd(struct gendisk *disk) static inline struct scsi_cd *scsi_cd(struct gendisk *disk)
{ {
return container_of(disk->private_data, struct scsi_cd, driver); return disk->private_data;
} }
static int sr_runtime_suspend(struct device *dev) static int sr_runtime_suspend(struct device *dev)
...@@ -692,7 +692,6 @@ static int sr_probe(struct device *dev) ...@@ -692,7 +692,6 @@ static int sr_probe(struct device *dev)
cd->device = sdev; cd->device = sdev;
cd->disk = disk; cd->disk = disk;
cd->driver = &sr_template;
cd->capacity = 0x1fffff; cd->capacity = 0x1fffff;
cd->device->changed = 1; /* force recheck CD type */ cd->device->changed = 1; /* force recheck CD type */
cd->media_present = 1; cd->media_present = 1;
...@@ -713,7 +712,7 @@ static int sr_probe(struct device *dev) ...@@ -713,7 +712,7 @@ static int sr_probe(struct device *dev)
sr_vendor_init(cd); sr_vendor_init(cd);
set_capacity(disk, cd->capacity); set_capacity(disk, cd->capacity);
disk->private_data = &cd->driver; disk->private_data = cd;
if (register_cdrom(disk, &cd->cdi)) if (register_cdrom(disk, &cd->cdi))
goto fail_minor; goto fail_minor;
......
...@@ -32,7 +32,6 @@ struct scsi_device; ...@@ -32,7 +32,6 @@ struct scsi_device;
typedef struct scsi_cd { typedef struct scsi_cd {
struct scsi_driver *driver;
unsigned capacity; /* size in blocks */ unsigned capacity; /* size in blocks */
struct scsi_device *device; struct scsi_device *device;
unsigned int vendor; /* vendor code, see sr_vendor.c */ unsigned int vendor; /* vendor code, see sr_vendor.c */
......
...@@ -4276,7 +4276,6 @@ static int st_probe(struct device *dev) ...@@ -4276,7 +4276,6 @@ static int st_probe(struct device *dev)
goto out_buffer_free; goto out_buffer_free;
} }
kref_init(&tpnt->kref); kref_init(&tpnt->kref);
tpnt->driver = &st_template;
tpnt->device = SDp; tpnt->device = SDp;
if (SDp->scsi_level <= 2) if (SDp->scsi_level <= 2)
......
...@@ -117,7 +117,6 @@ struct scsi_tape_stats { ...@@ -117,7 +117,6 @@ struct scsi_tape_stats {
/* The tape drive descriptor */ /* The tape drive descriptor */
struct scsi_tape { struct scsi_tape {
struct scsi_driver *driver;
struct scsi_device *device; struct scsi_device *device;
struct mutex lock; /* For serialization */ struct mutex lock; /* For serialization */
struct completion wait; /* For SCSI commands */ struct completion wait; /* For SCSI commands */
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include <scsi/scsi_request.h> #include <scsi/scsi_request.h>
struct Scsi_Host; struct Scsi_Host;
struct scsi_driver;
/* /*
* MAX_COMMAND_SIZE is: * MAX_COMMAND_SIZE is:
...@@ -159,14 +158,6 @@ static inline void *scsi_cmd_priv(struct scsi_cmnd *cmd) ...@@ -159,14 +158,6 @@ static inline void *scsi_cmd_priv(struct scsi_cmnd *cmd)
return cmd + 1; return cmd + 1;
} }
/* make sure not to use it with passthrough commands */
static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)
{
struct request *rq = scsi_cmd_to_rq(cmd);
return *(struct scsi_driver **)rq->q->disk->private_data;
}
void scsi_done(struct scsi_cmnd *cmd); void scsi_done(struct scsi_cmnd *cmd);
extern void scsi_finish_command(struct scsi_cmnd *cmd); extern void scsi_finish_command(struct scsi_cmnd *cmd);
......
...@@ -4,11 +4,10 @@ ...@@ -4,11 +4,10 @@
#include <linux/blk_types.h> #include <linux/blk_types.h>
#include <linux/device.h> #include <linux/device.h>
#include <scsi/scsi_cmnd.h>
struct module; struct module;
struct request; struct request;
struct scsi_cmnd;
struct scsi_device;
struct scsi_driver { struct scsi_driver {
struct device_driver gendrv; struct device_driver gendrv;
...@@ -31,4 +30,10 @@ extern int scsi_register_interface(struct class_interface *); ...@@ -31,4 +30,10 @@ extern int scsi_register_interface(struct class_interface *);
#define scsi_unregister_interface(intf) \ #define scsi_unregister_interface(intf) \
class_interface_unregister(intf) class_interface_unregister(intf)
/* make sure not to use it with passthrough commands */
static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)
{
return to_scsi_driver(cmd->device->sdev_gendev.driver);
}
#endif /* _SCSI_SCSI_DRIVER_H */ #endif /* _SCSI_SCSI_DRIVER_H */
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