Commit 9dd755d2 authored by Christoph Hellwig's avatar Christoph Hellwig

[PATCH] driver model for scsi upper drivers, take 2

On Tue, May 27, 2003 at 09:32:18AM +0200, Christoph Hellwig wrote:
>  - removed the tape sysfs pseudodevice crap that caused hangs
>  - switched sg to a class_interface.  This means sg can be used
>    on devices already claimed be an upper driver again.  This
>    also means I had to remove the sg sysfs attributes temporarily
>    because the old mechanism is gone, but I'll restore them
>    differently in a followon patch.

Yikes, this was the old patch again.  Here's the right one:
parent 83169a1a
...@@ -234,27 +234,18 @@ int scsi_remove_host(struct Scsi_Host *shost) ...@@ -234,27 +234,18 @@ int scsi_remove_host(struct Scsi_Host *shost)
int scsi_add_host(struct Scsi_Host *shost, struct device *dev) int scsi_add_host(struct Scsi_Host *shost, struct device *dev)
{ {
Scsi_Host_Template *sht = shost->hostt; Scsi_Host_Template *sht = shost->hostt;
struct scsi_device *sdev; int error;
int error = 0, saved_error = 0;
printk(KERN_INFO "scsi%d : %s\n", shost->host_no, printk(KERN_INFO "scsi%d : %s\n", shost->host_no,
sht->info ? sht->info(shost) : sht->name); sht->info ? sht->info(shost) : sht->name);
error = scsi_sysfs_add_host(shost, dev); error = scsi_sysfs_add_host(shost, dev);
if (error) if (!error) {
return error; scsi_proc_host_add(shost);
scsi_scan_host(shost);
scsi_proc_host_add(shost); };
scsi_scan_host(shost);
list_for_each_entry (sdev, &shost->my_devices, siblings) { return error;
error = scsi_attach_device(sdev);
if (error)
saved_error = error;
}
return saved_error;
} }
/** /**
......
...@@ -542,25 +542,23 @@ static inline struct device *scsi_get_device(struct Scsi_Host *shost) ...@@ -542,25 +542,23 @@ static inline struct device *scsi_get_device(struct Scsi_Host *shost)
return shost->host_gendev.parent; return shost->host_gendev.parent;
} }
struct Scsi_Device_Template struct scsi_driver {
{ struct module *owner;
struct list_head list; struct device_driver gendrv;
const char * name;
struct module * module; /* Used for loadable modules */ int (*init_command)(struct scsi_cmnd *);
unsigned char scsi_type; void (*rescan)(struct device *);
int (*attach)(Scsi_Device *); /* Attach devices to arrays */
void (*detach)(Scsi_Device *);
int (*init_command)(Scsi_Cmnd *); /* Used by new queueing code.
Selects command for blkdevs */
void (*rescan)(Scsi_Device *);
struct device_driver scsi_driverfs_driver;
}; };
#define to_scsi_driver(drv) \
container_of((drv), struct scsi_driver, gendrv)
/* extern int scsi_register_driver(struct device_driver *);
* Highlevel driver registration/unregistration. #define scsi_unregister_driver(drv) \
*/ driver_unregister(drv);
extern int scsi_register_device(struct Scsi_Device_Template *);
extern int scsi_unregister_device(struct Scsi_Device_Template *); extern int scsi_register_interface(struct class_interface *);
#define scsi_unregister_interface(intf) \
class_interface_unregister(intf)
/* /*
* HBA allocation/freeing. * HBA allocation/freeing.
......
...@@ -771,6 +771,10 @@ static inline struct bio *idescsi_dma_bio(ide_drive_t *drive, idescsi_pc_t *pc) ...@@ -771,6 +771,10 @@ static inline struct bio *idescsi_dma_bio(ide_drive_t *drive, idescsi_pc_t *pc)
static inline int should_transform(ide_drive_t *drive, Scsi_Cmnd *cmd) static inline int should_transform(ide_drive_t *drive, Scsi_Cmnd *cmd)
{ {
idescsi_scsi_t *scsi = drive_to_idescsi(drive); idescsi_scsi_t *scsi = drive_to_idescsi(drive);
/* this was a layering violation and we can't support it
anymore, sorry. */
#if 0
struct gendisk *disk = cmd->request->rq_disk; struct gendisk *disk = cmd->request->rq_disk;
if (disk) { if (disk) {
...@@ -778,6 +782,7 @@ static inline int should_transform(ide_drive_t *drive, Scsi_Cmnd *cmd) ...@@ -778,6 +782,7 @@ static inline int should_transform(ide_drive_t *drive, Scsi_Cmnd *cmd)
if (strcmp((*p)->scsi_driverfs_driver.name, "sg") == 0) if (strcmp((*p)->scsi_driverfs_driver.name, "sg") == 0)
return test_bit(IDESCSI_SG_TRANSFORM, &scsi->transform); return test_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
} }
#endif
return test_bit(IDESCSI_TRANSFORM, &scsi->transform); return test_bit(IDESCSI_TRANSFORM, &scsi->transform);
} }
......
...@@ -160,19 +160,15 @@ static int osst_zero_buffer_tail(OSST_buffer *); ...@@ -160,19 +160,15 @@ static int osst_zero_buffer_tail(OSST_buffer *);
static int osst_copy_to_buffer(OSST_buffer *, unsigned char *); static int osst_copy_to_buffer(OSST_buffer *, unsigned char *);
static int osst_copy_from_buffer(OSST_buffer *, unsigned char *); static int osst_copy_from_buffer(OSST_buffer *, unsigned char *);
static int osst_attach(Scsi_Device *); static int osst_probe(struct device *);
static void osst_detach(Scsi_Device *); static int osst_remove(struct device *);
struct Scsi_Device_Template osst_template = struct scsi_driver osst_template = {
{ .owner = THIS_MODULE,
.module = THIS_MODULE, .gendrv = {
.list = LIST_HEAD_INIT(osst_template.list), .name = "osst",
.name = "OnStream Tape", .probe = osst_probe,
.scsi_type = TYPE_TAPE, .remove = osst_remove,
.attach = osst_attach,
.detach = osst_detach,
.scsi_driverfs_driver = {
.name = "osst",
} }
}; };
...@@ -5326,22 +5322,6 @@ __setup("osst=", osst_setup); ...@@ -5326,22 +5322,6 @@ __setup("osst=", osst_setup);
#endif #endif
/* Driverfs file support */
static ssize_t osst_device_kdev_read(struct device *driverfs_dev, char *page)
{
kdev_t kdev;
kdev.value=(int)(long)driverfs_dev->driver_data;
return sprintf(page, "%x\n",kdev.value);
}
static DEVICE_ATTR(kdev,S_IRUGO,osst_device_kdev_read,NULL);
static ssize_t osst_device_type_read(struct device *driverfs_dev, char *page)
{
return sprintf (page, "CHR\n");
}
static DEVICE_ATTR(type,S_IRUGO,osst_device_type_read,NULL);
static struct file_operations osst_fops = { static struct file_operations osst_fops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.read = osst_read, .read = osst_read,
...@@ -5384,8 +5364,9 @@ static struct osst_support_data support_list[] = { ...@@ -5384,8 +5364,9 @@ static struct osst_support_data support_list[] = {
* osst startup / cleanup code * osst startup / cleanup code
*/ */
static int osst_attach(Scsi_Device * SDp) static int osst_probe(struct device *dev)
{ {
Scsi_Device * SDp = to_scsi_device(dev);
OS_Scsi_Tape * tpnt; OS_Scsi_Tape * tpnt;
ST_mode * STm; ST_mode * STm;
ST_partstat * STps; ST_partstat * STps;
...@@ -5394,12 +5375,12 @@ static int osst_attach(Scsi_Device * SDp) ...@@ -5394,12 +5375,12 @@ static int osst_attach(Scsi_Device * SDp)
int i, mode, dev_num; int i, mode, dev_num;
if (SDp->type != TYPE_TAPE || !osst_supports(SDp)) if (SDp->type != TYPE_TAPE || !osst_supports(SDp))
return 1; return -ENODEV;
drive = alloc_disk(1); drive = alloc_disk(1);
if (!drive) { if (!drive) {
printk(KERN_ERR "osst :E: Out of memory. Device not attached.\n"); printk(KERN_ERR "osst :E: Out of memory. Device not attached.\n");
return 1; return -ENODEV;
} }
/* if this is the first attach, build the infrastructure */ /* if this is the first attach, build the infrastructure */
...@@ -5521,45 +5502,12 @@ static int osst_attach(Scsi_Device * SDp) ...@@ -5521,45 +5502,12 @@ static int osst_attach(Scsi_Device * SDp)
write_unlock(&os_scsi_tapes_lock); write_unlock(&os_scsi_tapes_lock);
for (mode = 0; mode < ST_NBR_MODES; ++mode) { for (mode = 0; mode < ST_NBR_MODES; ++mode) {
char name[8];
/* Rewind entry */ /* Rewind entry */
sprintf(name, "ot%s", osst_formats[mode]);
sprintf(tpnt->driverfs_dev_r[mode].bus_id, "%s:%s",
SDp->sdev_driverfs_dev.bus_id, name);
sprintf(tpnt->driverfs_dev_r[mode].name, "%s%s",
SDp->sdev_driverfs_dev.name, name);
tpnt->driverfs_dev_r[mode].parent = &SDp->sdev_driverfs_dev;
tpnt->driverfs_dev_r[mode].bus = SDp->sdev_driverfs_dev.bus;
tpnt->driverfs_dev_r[mode].driver_data =
(void *)(long)__mkdev(OSST_MAJOR, dev_num + (mode << 5));
device_register(&tpnt->driverfs_dev_r[mode]);
device_create_file(&tpnt->driverfs_dev_r[mode],
&dev_attr_type);
device_create_file(&tpnt->driverfs_dev_r[mode], &dev_attr_kdev);
devfs_mk_cdev(MKDEV(OSST_MAJOR, dev_num + (mode << 5)), devfs_mk_cdev(MKDEV(OSST_MAJOR, dev_num + (mode << 5)),
S_IFCHR | S_IRUGO | S_IWUGO, S_IFCHR | S_IRUGO | S_IWUGO,
"%s/ot%s", SDp->devfs_name, osst_formats[mode]); "%s/ot%s", SDp->devfs_name, osst_formats[mode]);
/* No-rewind entry */ /* No-rewind entry */
sprintf (name, "ot%sn", osst_formats[mode]);
sprintf(tpnt->driverfs_dev_n[mode].bus_id, "%s:%s",
SDp->sdev_driverfs_dev.bus_id, name);
sprintf(tpnt->driverfs_dev_n[mode].name, "%s%s",
SDp->sdev_driverfs_dev.name, name);
tpnt->driverfs_dev_n[mode].parent= &SDp->sdev_driverfs_dev;
tpnt->driverfs_dev_n[mode].bus = SDp->sdev_driverfs_dev.bus;
tpnt->driverfs_dev_n[mode].driver_data =
(void *)(long)__mkdev(OSST_MAJOR, dev_num + (mode << 5) + 128);
device_register(&tpnt->driverfs_dev_n[mode]);
device_create_file(&tpnt->driverfs_dev_n[mode],
&dev_attr_type);
device_create_file(&tpnt->driverfs_dev_n[mode],
&dev_attr_kdev);
devfs_mk_cdev(MKDEV(OSST_MAJOR, dev_num + (mode << 5) + 128), devfs_mk_cdev(MKDEV(OSST_MAJOR, dev_num + (mode << 5) + 128),
S_IFCHR | S_IRUGO | S_IWUGO, S_IFCHR | S_IRUGO | S_IWUGO,
"%s/ot%sn", SDp->devfs_name, osst_formats[mode]); "%s/ot%sn", SDp->devfs_name, osst_formats[mode]);
...@@ -5574,16 +5522,17 @@ static int osst_attach(Scsi_Device * SDp) ...@@ -5574,16 +5522,17 @@ static int osst_attach(Scsi_Device * SDp)
out_put_disk: out_put_disk:
put_disk(drive); put_disk(drive);
return 1; return -ENODEV;
}; };
static void osst_detach(Scsi_Device * SDp) static int osst_remove(struct device *dev)
{ {
Scsi_Device * SDp = to_scsi_device(dev);
OS_Scsi_Tape * tpnt; OS_Scsi_Tape * tpnt;
int i, mode; int i, mode;
if ((SDp->type != TYPE_TAPE) || (osst_nr_dev <= 0)) if ((SDp->type != TYPE_TAPE) || (osst_nr_dev <= 0))
return; return 0;
write_lock(&os_scsi_tapes_lock); write_lock(&os_scsi_tapes_lock);
for(i=0; i < osst_max_dev; i++) { for(i=0; i < osst_max_dev; i++) {
...@@ -5598,29 +5547,17 @@ static void osst_detach(Scsi_Device * SDp) ...@@ -5598,29 +5547,17 @@ static void osst_detach(Scsi_Device * SDp)
os_scsi_tapes[i] = NULL; os_scsi_tapes[i] = NULL;
osst_nr_dev--; osst_nr_dev--;
write_unlock(&os_scsi_tapes_lock); write_unlock(&os_scsi_tapes_lock);
for (mode = 0; mode < ST_NBR_MODES; ++mode) {
device_remove_file(&tpnt->driverfs_dev_r[mode],
&dev_attr_type);
device_remove_file(&tpnt->driverfs_dev_r[mode],
&dev_attr_kdev);
device_unregister(&tpnt->driverfs_dev_r[mode]);
device_remove_file(&tpnt->driverfs_dev_n[mode],
&dev_attr_type);
device_remove_file(&tpnt->driverfs_dev_n[mode],
&dev_attr_kdev);
device_unregister(&tpnt->driverfs_dev_n[mode]);
}
if (tpnt->header_cache != NULL) vfree(tpnt->header_cache); if (tpnt->header_cache != NULL) vfree(tpnt->header_cache);
if (tpnt->buffer) { if (tpnt->buffer) {
normalize_buffer(tpnt->buffer); normalize_buffer(tpnt->buffer);
kfree(tpnt->buffer); kfree(tpnt->buffer);
} }
kfree(tpnt); kfree(tpnt);
return; return 0;
} }
} }
write_unlock(&os_scsi_tapes_lock); write_unlock(&os_scsi_tapes_lock);
return; return 0;
} }
static int __init init_osst(void) static int __init init_osst(void)
...@@ -5629,7 +5566,7 @@ static int __init init_osst(void) ...@@ -5629,7 +5566,7 @@ static int __init init_osst(void)
validate_options(); validate_options();
if ((register_chrdev(OSST_MAJOR,"osst", &osst_fops) < 0) || scsi_register_device(&osst_template)) { if ((register_chrdev(OSST_MAJOR,"osst", &osst_fops) < 0) || scsi_register_driver(&osst_template.gendrv)) {
printk(KERN_ERR "osst :E: Unable to register major %d for OnStream tapes\n", OSST_MAJOR); printk(KERN_ERR "osst :E: Unable to register major %d for OnStream tapes\n", OSST_MAJOR);
return 1; return 1;
} }
...@@ -5642,7 +5579,7 @@ static void __exit exit_osst (void) ...@@ -5642,7 +5579,7 @@ static void __exit exit_osst (void)
int i; int i;
OS_Scsi_Tape * STp; OS_Scsi_Tape * STp;
scsi_unregister_device(&osst_template); scsi_unregister_driver(&osst_template.gendrv);
unregister_chrdev(OSST_MAJOR, "osst"); unregister_chrdev(OSST_MAJOR, "osst");
if (os_scsi_tapes) { if (os_scsi_tapes) {
......
...@@ -530,7 +530,7 @@ typedef struct { ...@@ -530,7 +530,7 @@ typedef struct {
/* The OnStream tape drive descriptor */ /* The OnStream tape drive descriptor */
typedef struct { typedef struct {
struct Scsi_Device_Template *driver; struct scsi_driver *driver;
unsigned capacity; unsigned capacity;
Scsi_Device* device; Scsi_Device* device;
struct semaphore lock; /* for serialization */ struct semaphore lock; /* for serialization */
...@@ -555,8 +555,6 @@ typedef struct { ...@@ -555,8 +555,6 @@ typedef struct {
/* Mode characteristics */ /* Mode characteristics */
ST_mode modes[ST_NBR_MODES]; ST_mode modes[ST_NBR_MODES];
int current_mode; int current_mode;
struct device driverfs_dev_r[ST_NBR_MODES];
struct device driverfs_dev_n[ST_NBR_MODES];
/* Status variables */ /* Status variables */
int partition; int partition;
......
...@@ -85,12 +85,6 @@ unsigned long scsi_pid; ...@@ -85,12 +85,6 @@ unsigned long scsi_pid;
struct scsi_cmnd *last_cmnd; struct scsi_cmnd *last_cmnd;
static unsigned long serial_number; static unsigned long serial_number;
/*
* List of all highlevel drivers.
*/
LIST_HEAD(scsi_devicelist);
static DECLARE_RWSEM(scsi_devicelist_mutex);
/* /*
* Note - the initial logging level can be set here to log events at boot time. * Note - the initial logging level can be set here to log events at boot time.
* After the system is up, you may enable logging via the /proc interface. * After the system is up, you may enable logging via the /proc interface.
...@@ -931,50 +925,6 @@ int scsi_track_queue_full(struct scsi_device *sdev, int depth) ...@@ -931,50 +925,6 @@ int scsi_track_queue_full(struct scsi_device *sdev, int depth)
return depth; return depth;
} }
int scsi_attach_device(struct scsi_device *sdev)
{
struct Scsi_Device_Template *sdt;
down_read(&scsi_devicelist_mutex);
list_for_each_entry(sdt, &scsi_devicelist, list) {
if (!try_module_get(sdt->module))
continue;
(*sdt->attach)(sdev);
module_put(sdt->module);
}
up_read(&scsi_devicelist_mutex);
return 0;
}
void scsi_detach_device(struct scsi_device *sdev)
{
struct Scsi_Device_Template *sdt;
down_read(&scsi_devicelist_mutex);
list_for_each_entry(sdt, &scsi_devicelist, list) {
if (!try_module_get(sdt->module))
continue;
(*sdt->detach)(sdev);
module_put(sdt->module);
}
up_read(&scsi_devicelist_mutex);
}
void scsi_rescan_device(struct scsi_device *sdev)
{
struct Scsi_Device_Template *sdt;
down_read(&scsi_devicelist_mutex);
list_for_each_entry(sdt, &scsi_devicelist, list) {
if (!try_module_get(sdt->module))
continue;
if (*sdt->rescan)
(*sdt->rescan)(sdev);
module_put(sdt->module);
}
up_read(&scsi_devicelist_mutex);
}
int scsi_device_get(struct scsi_device *sdev) int scsi_device_get(struct scsi_device *sdev)
{ {
if (!try_module_get(sdev->host->hostt->module)) if (!try_module_get(sdev->host->hostt->module))
...@@ -1030,71 +980,6 @@ void scsi_set_device_offline(struct scsi_device *sdev) ...@@ -1030,71 +980,6 @@ void scsi_set_device_offline(struct scsi_device *sdev)
} }
} }
/*
* This entry point is called from the upper level module's module_init()
* routine. That implies that when this function is called, the
* scsi_mod module is locked down because of upper module layering and
* that the high level driver module is locked down by being in it's
* init routine. So, the *only* thing we have to do to protect adds
* we perform in this function is to make sure that all call's
* to the high level driver's attach() and detach() call in points, other
* than via scsi_register_device and scsi_unregister_device which are in
* the module_init and module_exit code respectively and therefore already
* locked down by the kernel module loader, are wrapped by try_module_get()
* and module_put() to avoid races on device adds and removes.
*/
int scsi_register_device(struct Scsi_Device_Template *tpnt)
{
struct scsi_device *sdev;
struct Scsi_Host *shpnt;
#ifdef CONFIG_KMOD
if (scsi_host_get_next(NULL) == NULL)
request_module("scsi_hostadapter");
#endif
if (!list_empty(&tpnt->list))
return 1;
down_write(&scsi_devicelist_mutex);
list_add_tail(&tpnt->list, &scsi_devicelist);
up_write(&scsi_devicelist_mutex);
scsi_upper_driver_register(tpnt);
for (shpnt = scsi_host_get_next(NULL); shpnt;
shpnt = scsi_host_get_next(shpnt))
list_for_each_entry(sdev, &shpnt->my_devices, siblings)
(*tpnt->attach)(sdev);
return 0;
}
int scsi_unregister_device(struct Scsi_Device_Template *tpnt)
{
struct scsi_device *sdev;
struct Scsi_Host *shpnt;
/*
* Next, detach the devices from the driver.
*/
for (shpnt = scsi_host_get_next(NULL); shpnt;
shpnt = scsi_host_get_next(shpnt)) {
list_for_each_entry(sdev, &shpnt->my_devices, siblings)
(*tpnt->detach)(sdev);
}
/*
* Extract the template from the linked list.
*/
down_write(&scsi_devicelist_mutex);
list_del(&tpnt->list);
up_write(&scsi_devicelist_mutex);
scsi_upper_driver_unregister(tpnt);
return 0;
}
MODULE_DESCRIPTION("SCSI core"); MODULE_DESCRIPTION("SCSI core");
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
......
...@@ -316,6 +316,7 @@ extern const char *scsi_extd_sense_format(unsigned char, unsigned char); ...@@ -316,6 +316,7 @@ extern const char *scsi_extd_sense_format(unsigned char, unsigned char);
*/ */
struct scsi_device { struct scsi_device {
struct class_device sdev_classdev;
/* /*
* This information is private to the scsi mid-layer. * This information is private to the scsi mid-layer.
*/ */
......
...@@ -612,29 +612,6 @@ static void scsi_release_buffers(struct scsi_cmnd *cmd) ...@@ -612,29 +612,6 @@ static void scsi_release_buffers(struct scsi_cmnd *cmd)
cmd->request_bufflen = 0; cmd->request_bufflen = 0;
} }
/*
* Function: scsi_get_request_dev()
*
* Purpose: Find the upper-level driver that is responsible for this
* request
*
* Arguments: request - I/O request we are preparing to queue.
*
* Lock status: No locks assumed to be held, but as it happens the
* q->queue_lock is held when this is called.
*
* Returns: Nothing
*
* Notes: The requests in the request queue may have originated
* from any block device driver. We need to find out which
* one so that we can later form the appropriate command.
*/
static struct Scsi_Device_Template *scsi_get_request_dev(struct request *req)
{
struct gendisk *p = req->rq_disk;
return p ? *(struct Scsi_Device_Template **)p->private_data : NULL;
}
/* /*
* Function: scsi_io_completion() * Function: scsi_io_completion()
* *
...@@ -849,11 +826,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, int good_sectors, ...@@ -849,11 +826,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, int good_sectors,
return; return;
} }
if (result) { if (result) {
struct Scsi_Device_Template *sdt; printk("SCSI error : <%d %d %d %d> return code = 0x%x\n",
sdt = scsi_get_request_dev(cmd->request);
printk("SCSI %s error : <%d %d %d %d> return code = 0x%x\n",
(sdt ? sdt->name : "device"),
cmd->device->host->host_no, cmd->device->host->host_no,
cmd->device->channel, cmd->device->channel,
cmd->device->id, cmd->device->id,
...@@ -947,7 +920,6 @@ static int scsi_init_io(struct scsi_cmnd *cmd) ...@@ -947,7 +920,6 @@ static int scsi_init_io(struct scsi_cmnd *cmd)
static int scsi_prep_fn(struct request_queue *q, struct request *req) static int scsi_prep_fn(struct request_queue *q, struct request *req)
{ {
struct Scsi_Device_Template *sdt;
struct scsi_device *sdev = q->queuedata; struct scsi_device *sdev = q->queuedata;
struct scsi_cmnd *cmd; struct scsi_cmnd *cmd;
...@@ -1003,6 +975,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) ...@@ -1003,6 +975,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
* happening now. * happening now.
*/ */
if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) { if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) {
struct scsi_driver *drv;
int ret; int ret;
/* /*
...@@ -1017,8 +990,6 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) ...@@ -1017,8 +990,6 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
* some kinds of consistency checking may cause the * some kinds of consistency checking may cause the
* request to be rejected immediately. * request to be rejected immediately.
*/ */
sdt = scsi_get_request_dev(req);
BUG_ON(!sdt);
/* /*
* This sets up the scatter-gather table (allocating if * This sets up the scatter-gather table (allocating if
...@@ -1031,7 +1002,8 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) ...@@ -1031,7 +1002,8 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req)
/* /*
* Initialize the actual SCSI command for this request. * Initialize the actual SCSI command for this request.
*/ */
if (unlikely(!sdt->init_command(cmd))) { drv = *(struct scsi_driver **)req->rq_disk->private_data;
if (unlikely(!drv->init_command(cmd))) {
scsi_release_buffers(cmd); scsi_release_buffers(cmd);
scsi_put_command(cmd); scsi_put_command(cmd);
return BLKPREP_KILL; return BLKPREP_KILL;
......
...@@ -41,9 +41,6 @@ ...@@ -41,9 +41,6 @@
#define SCSI_SENSE_VALID(scmd) \ #define SCSI_SENSE_VALID(scmd) \
(((scmd)->sense_buffer[0] & 0x70) == 0x70) (((scmd)->sense_buffer[0] & 0x70) == 0x70)
struct Scsi_Device_Template;
/* /*
* scsi_target: representation of a scsi target, for now, this is only * scsi_target: representation of a scsi target, for now, this is only
* used for single_lun devices. If no one has active IO to the target, * used for single_lun devices. If no one has active IO to the target,
...@@ -70,9 +67,6 @@ extern void scsi_destroy_command_freelist(struct Scsi_Host *shost); ...@@ -70,9 +67,6 @@ extern void scsi_destroy_command_freelist(struct Scsi_Host *shost);
extern void scsi_done(struct scsi_cmnd *cmd); extern 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);
extern int scsi_retry_command(struct scsi_cmnd *cmd); extern int scsi_retry_command(struct scsi_cmnd *cmd);
extern int scsi_attach_device(struct scsi_device *sdev);
extern void scsi_detach_device(struct scsi_device *sdev);
extern void scsi_rescan_device(struct scsi_device *sdev);
extern int scsi_insert_special_req(struct scsi_request *sreq, int); extern int scsi_insert_special_req(struct scsi_request *sreq, int);
extern void scsi_init_cmd_from_req(struct scsi_cmnd *cmd, extern void scsi_init_cmd_from_req(struct scsi_cmnd *cmd,
struct scsi_request *sreq); struct scsi_request *sreq);
...@@ -119,12 +113,11 @@ extern void scsi_forget_host(struct Scsi_Host *shost); ...@@ -119,12 +113,11 @@ extern void scsi_forget_host(struct Scsi_Host *shost);
extern void scsi_free_sdev(struct scsi_device *); extern void scsi_free_sdev(struct scsi_device *);
extern void scsi_free_shost(struct Scsi_Host *); extern void scsi_free_shost(struct Scsi_Host *);
extern void scsi_host_get(struct Scsi_Host *); extern void scsi_host_get(struct Scsi_Host *);
extern void scsi_rescan_device(struct device *dev);
/* scsi_sysfs.c */ /* scsi_sysfs.c */
extern int scsi_device_register(struct scsi_device *); extern int scsi_device_register(struct scsi_device *);
extern void scsi_device_unregister(struct scsi_device *); extern void scsi_device_unregister(struct scsi_device *);
extern int scsi_upper_driver_register(struct Scsi_Device_Template *);
extern void scsi_upper_driver_unregister(struct Scsi_Device_Template *);
extern void scsi_sysfs_init_host(struct Scsi_Host *); extern void scsi_sysfs_init_host(struct Scsi_Host *);
extern int scsi_sysfs_add_host(struct Scsi_Host *, struct device *); extern int scsi_sysfs_add_host(struct Scsi_Host *, struct device *);
extern void scsi_sysfs_remove_host(struct Scsi_Host *); extern void scsi_sysfs_remove_host(struct Scsi_Host *);
......
...@@ -1098,24 +1098,31 @@ struct scsi_device *scsi_add_device(struct Scsi_Host *shost, ...@@ -1098,24 +1098,31 @@ struct scsi_device *scsi_add_device(struct Scsi_Host *shost,
uint channel, uint id, uint lun) uint channel, uint id, uint lun)
{ {
struct scsi_device *sdev; struct scsi_device *sdev;
int error = -ENODEV, res; int res;
res = scsi_probe_and_add_lun(shost, channel, id, lun, NULL, &sdev); res = scsi_probe_and_add_lun(shost, channel, id, lun, NULL, &sdev);
if (res == SCSI_SCAN_LUN_PRESENT) if (res != SCSI_SCAN_LUN_PRESENT)
error = scsi_attach_device(sdev); sdev = ERR_PTR(-ENODEV);
if (error)
sdev = ERR_PTR(error);
return sdev; return sdev;
} }
int scsi_remove_device(struct scsi_device *sdev) int scsi_remove_device(struct scsi_device *sdev)
{ {
scsi_detach_device(sdev);
scsi_device_unregister(sdev); scsi_device_unregister(sdev);
return 0; return 0;
} }
void scsi_rescan_device(struct device *dev)
{
struct scsi_driver *drv = to_scsi_driver(dev->driver);
if (try_module_get(drv->owner)) {
if (drv->rescan)
drv->rescan(dev);
module_put(drv->owner);
}
}
/** /**
* scsi_scan_target - scan a target id, possibly including all LUNs on the * scsi_scan_target - scan a target id, possibly including all LUNs on the
* target. * target.
......
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
* This source file contains the symbol table used by scsi loadable * This source file contains the symbol table used by scsi loadable
* modules. * modules.
*/ */
EXPORT_SYMBOL(scsi_register_device); EXPORT_SYMBOL(scsi_register_driver);
EXPORT_SYMBOL(scsi_unregister_device); EXPORT_SYMBOL(scsi_register_interface);
EXPORT_SYMBOL(scsi_register_host); EXPORT_SYMBOL(scsi_register_host);
EXPORT_SYMBOL(scsi_unregister_host); EXPORT_SYMBOL(scsi_unregister_host);
EXPORT_SYMBOL(scsi_add_host); EXPORT_SYMBOL(scsi_add_host);
......
...@@ -58,32 +58,16 @@ static struct class shost_class = { ...@@ -58,32 +58,16 @@ static struct class shost_class = {
.name = "scsi_host", .name = "scsi_host",
}; };
/** static struct class sdev_class = {
* scsi_bus_match: .name = "scsi_device",
* @dev: };
* @dev_driver:
* /* all probing is done in the individual ->probe routines */
* Return value: static int scsi_bus_match(struct device *dev, struct device_driver *gendrv)
**/
static int scsi_bus_match(struct device *dev,
struct device_driver *dev_driver)
{ {
if (!strcmp("sg", dev_driver->name)) { return 1;
if (strstr(dev->bus_id, ":gen"))
return 1;
} else if (!strcmp("st",dev_driver->name)) {
if (strstr(dev->bus_id,":mt"))
return 1;
} else if (!strcmp("sd", dev_driver->name)) {
if ((!strstr(dev->bus_id, ":gen")) &&
(!strstr(dev->bus_id, ":mt"))) {
return 1;
}
}
return 0;
} }
static struct bus_type scsi_bus_type = { static struct bus_type scsi_bus_type = {
.name = "scsi", .name = "scsi",
.match = scsi_bus_match, .match = scsi_bus_match,
...@@ -99,45 +83,26 @@ int scsi_sysfs_register(void) ...@@ -99,45 +83,26 @@ int scsi_sysfs_register(void)
return error; return error;
error = class_register(&shost_class); error = class_register(&shost_class);
if (error) if (error)
return error; goto bus_unregister;
error = class_register(&sdev_class);
if (error)
goto class_unregister;
return 0;
class_unregister:
class_unregister(&shost_class);
bus_unregister:
bus_unregister(&scsi_bus_type);
return error; return error;
} }
void scsi_sysfs_unregister(void) void scsi_sysfs_unregister(void)
{ {
class_unregister(&sdev_class);
class_unregister(&shost_class); class_unregister(&shost_class);
bus_unregister(&scsi_bus_type); bus_unregister(&scsi_bus_type);
} }
/**
* scsi_upper_driver_register - register upper level driver.
* @sdev_tp: Upper level driver to register with the scsi bus.
*
* Return value:
* 0 on Success / non-zero on Failure
**/
int scsi_upper_driver_register(struct Scsi_Device_Template *sdev_tp)
{
int error = 0;
sdev_tp->scsi_driverfs_driver.bus = &scsi_bus_type;
error = driver_register(&sdev_tp->scsi_driverfs_driver);
return error;
}
/**
* scsi_upper_driver_unregister - unregister upper level driver
* @sdev_tp: Upper level driver to unregister with the scsi bus.
*
**/
void scsi_upper_driver_unregister(struct Scsi_Device_Template *sdev_tp)
{
driver_unregister(&sdev_tp->scsi_driverfs_driver);
}
/* /*
* sdev_show_function: macro to create an attr function that can be used to * sdev_show_function: macro to create an attr function that can be used to
* show a non-bit field. * show a non-bit field.
...@@ -238,7 +203,7 @@ show_rescan_field (struct device *dev, char *buf) ...@@ -238,7 +203,7 @@ show_rescan_field (struct device *dev, char *buf)
static ssize_t static ssize_t
store_rescan_field (struct device *dev, const char *buf, size_t count) store_rescan_field (struct device *dev, const char *buf, size_t count)
{ {
scsi_rescan_device(to_scsi_device(dev)); scsi_rescan_device(dev);
return 0; return 0;
} }
...@@ -280,15 +245,30 @@ int scsi_device_register(struct scsi_device *sdev) ...@@ -280,15 +245,30 @@ int scsi_device_register(struct scsi_device *sdev)
{ {
int error = 0, i; int error = 0, i;
device_initialize(&sdev->sdev_driverfs_dev);
sprintf(sdev->sdev_driverfs_dev.bus_id,"%d:%d:%d:%d", sprintf(sdev->sdev_driverfs_dev.bus_id,"%d:%d:%d:%d",
sdev->host->host_no, sdev->channel, sdev->id, sdev->lun); sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
sdev->sdev_driverfs_dev.parent = &sdev->host->host_gendev; sdev->sdev_driverfs_dev.parent = &sdev->host->host_gendev;
sdev->sdev_driverfs_dev.bus = &scsi_bus_type; sdev->sdev_driverfs_dev.bus = &scsi_bus_type;
sdev->sdev_driverfs_dev.release = scsi_device_release; sdev->sdev_driverfs_dev.release = scsi_device_release;
error = device_register(&sdev->sdev_driverfs_dev); class_device_initialize(&sdev->sdev_classdev);
if (error) sdev->sdev_classdev.dev = &sdev->sdev_driverfs_dev;
sdev->sdev_classdev.class = &sdev_class;
snprintf(sdev->sdev_classdev.class_id, BUS_ID_SIZE, "%d:%d:%d:%d",
sdev->host->host_no, sdev->channel, sdev->id, sdev->lun);
error = device_add(&sdev->sdev_driverfs_dev);
if (error) {
printk(KERN_INFO "error 1\n");
return error; return error;
}
error = class_device_add(&sdev->sdev_classdev);
if (error) {
printk(KERN_INFO "error 2\n");
device_unregister(&sdev->sdev_driverfs_dev);
return error;
}
for (i = 0; !error && sdev->host->hostt->sdev_attrs[i] != NULL; i++) for (i = 0; !error && sdev->host->hostt->sdev_attrs[i] != NULL; i++)
error = device_create_file(&sdev->sdev_driverfs_dev, error = device_create_file(&sdev->sdev_driverfs_dev,
...@@ -310,9 +290,24 @@ void scsi_device_unregister(struct scsi_device *sdev) ...@@ -310,9 +290,24 @@ void scsi_device_unregister(struct scsi_device *sdev)
for (i = 0; sdev->host->hostt->sdev_attrs[i] != NULL; i++) for (i = 0; sdev->host->hostt->sdev_attrs[i] != NULL; i++)
device_remove_file(&sdev->sdev_driverfs_dev, sdev->host->hostt->sdev_attrs[i]); device_remove_file(&sdev->sdev_driverfs_dev, sdev->host->hostt->sdev_attrs[i]);
class_device_unregister(&sdev->sdev_classdev);
device_unregister(&sdev->sdev_driverfs_dev); device_unregister(&sdev->sdev_driverfs_dev);
} }
int scsi_register_driver(struct device_driver *drv)
{
drv->bus = &scsi_bus_type;
return driver_register(drv);
}
int scsi_register_interface(struct class_interface *intf)
{
intf->class = &sdev_class;
return class_interface_register(intf);
}
static void scsi_host_release(struct device *dev) static void scsi_host_release(struct device *dev)
{ {
struct Scsi_Host *shost; struct Scsi_Host *shost;
...@@ -350,7 +345,7 @@ int scsi_sysfs_add_host(struct Scsi_Host *shost, struct device *dev) ...@@ -350,7 +345,7 @@ int scsi_sysfs_add_host(struct Scsi_Host *shost, struct device *dev)
int i, error; int i, error;
if (!shost->host_gendev.parent) if (!shost->host_gendev.parent)
shost->host_gendev.parent = (dev) ? dev : &legacy_bus; shost->host_gendev.parent = dev ? dev : &legacy_bus;
error = device_add(&shost->host_gendev); error = device_add(&shost->host_gendev);
if (error) if (error)
......
...@@ -73,8 +73,7 @@ ...@@ -73,8 +73,7 @@
#define SD_MAX_RETRIES 5 #define SD_MAX_RETRIES 5
struct scsi_disk { struct scsi_disk {
struct list_head list; /* list of all scsi_disks */ struct scsi_driver *driver; /* always &sd_template */
struct Scsi_Device_Template *driver; /* always &sd_template */
struct scsi_device *device; struct scsi_device *device;
struct gendisk *disk; struct gendisk *disk;
sector_t capacity; /* size in 512-byte sectors */ sector_t capacity; /* size in 512-byte sectors */
...@@ -85,37 +84,31 @@ struct scsi_disk { ...@@ -85,37 +84,31 @@ struct scsi_disk {
unsigned RCD : 1; /* state of disk RCD bit, unused */ unsigned RCD : 1; /* state of disk RCD bit, unused */
}; };
static LIST_HEAD(sd_devlist);
static spinlock_t sd_devlist_lock = SPIN_LOCK_UNLOCKED;
static unsigned long sd_index_bits[SD_DISKS / BITS_PER_LONG]; static unsigned long sd_index_bits[SD_DISKS / BITS_PER_LONG];
static spinlock_t sd_index_lock = SPIN_LOCK_UNLOCKED; static spinlock_t sd_index_lock = SPIN_LOCK_UNLOCKED;
static void sd_init_onedisk(struct scsi_disk * sdkp, struct gendisk *disk); static void sd_init_onedisk(struct scsi_disk * sdkp, struct gendisk *disk);
static void sd_rw_intr(struct scsi_cmnd * SCpnt); static void sd_rw_intr(struct scsi_cmnd * SCpnt);
static int sd_attach(struct scsi_device *); static int sd_probe(struct device *);
static void sd_detach(struct scsi_device *); static int sd_remove(struct device *);
static void sd_rescan(struct scsi_device *); static void sd_shutdown(struct device *dev);
static void sd_rescan(struct device *);
static int sd_init_command(struct scsi_cmnd *); static int sd_init_command(struct scsi_cmnd *);
static int sd_synchronize_cache(struct scsi_disk *, int); static int sd_synchronize_cache(struct scsi_disk *, int);
static int sd_notifier(struct notifier_block *, unsigned long, void *);
static void sd_read_capacity(struct scsi_disk *sdkp, char *diskname, static void sd_read_capacity(struct scsi_disk *sdkp, char *diskname,
struct scsi_request *SRpnt, unsigned char *buffer); struct scsi_request *SRpnt, unsigned char *buffer);
static struct notifier_block sd_notifier_block = {sd_notifier, NULL, 0};
static struct scsi_driver sd_template = {
static struct Scsi_Device_Template sd_template = { .owner = THIS_MODULE,
.module = THIS_MODULE, .gendrv = {
.list = LIST_HEAD_INIT(sd_template.list), .name = "sd",
.name = "disk", .probe = sd_probe,
.scsi_type = TYPE_DISK, .remove = sd_remove,
.attach = sd_attach, .shutdown = sd_shutdown,
.detach = sd_detach,
.rescan = sd_rescan,
.init_command = sd_init_command,
.scsi_driverfs_driver = {
.name = "sd",
}, },
.rescan = sd_rescan,
.init_command = sd_init_command,
}; };
static int sd_major(int major_idx) static int sd_major(int major_idx)
...@@ -133,36 +126,6 @@ static int sd_major(int major_idx) ...@@ -133,36 +126,6 @@ static int sd_major(int major_idx)
} }
} }
static struct scsi_disk *sd_find_by_sdev(Scsi_Device *sd)
{
struct scsi_disk *sdkp;
spin_lock(&sd_devlist_lock);
list_for_each_entry(sdkp, &sd_devlist, list) {
if (sdkp->device == sd) {
spin_unlock(&sd_devlist_lock);
return sdkp;
}
}
spin_unlock(&sd_devlist_lock);
return NULL;
}
static inline void sd_devlist_insert(struct scsi_disk *sdkp)
{
spin_lock(&sd_devlist_lock);
list_add(&sdkp->list, &sd_devlist);
spin_unlock(&sd_devlist_lock);
}
static inline void sd_devlist_remove(struct scsi_disk *sdkp)
{
spin_lock(&sd_devlist_lock);
list_del(&sdkp->list);
spin_unlock(&sd_devlist_lock);
}
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 container_of(disk->private_data, struct scsi_disk, driver);
...@@ -636,12 +599,13 @@ static int sd_media_changed(struct gendisk *disk) ...@@ -636,12 +599,13 @@ static int sd_media_changed(struct gendisk *disk)
return 1; return 1;
} }
static void sd_rescan(struct scsi_device * sdp) static void sd_rescan(struct device *dev)
{ {
unsigned char *buffer; struct scsi_device *sdp = to_scsi_device(dev);
struct scsi_disk *sdkp = sd_find_by_sdev(sdp); struct scsi_disk *sdkp = dev_get_drvdata(dev);
struct gendisk *gd; struct gendisk *gd;
struct scsi_request *SRpnt; struct scsi_request *SRpnt;
unsigned char *buffer;
if (!sdkp || sdp->online == FALSE || !sdkp->media_present) if (!sdkp || sdp->online == FALSE || !sdkp->media_present)
return; return;
...@@ -1312,10 +1276,10 @@ sd_init_onedisk(struct scsi_disk * sdkp, struct gendisk *disk) ...@@ -1312,10 +1276,10 @@ sd_init_onedisk(struct scsi_disk * sdkp, struct gendisk *disk)
} }
/** /**
* sd_attach - called during driver initialization and whenever a * sd_probe - called during driver initialization and whenever a
* new scsi device is attached to the system. It is called once * new scsi device is attached to the system. It is called once
* for each scsi device (not just disks) present. * for each scsi device (not just disks) present.
* @sdp: pointer to mid level scsi device object * @dev: pointer to device object
* *
* Returns 0 if successful (or not interested in this scsi device * Returns 0 if successful (or not interested in this scsi device
* (e.g. scanner)); 1 when there is an error. * (e.g. scanner)); 1 when there is an error.
...@@ -1327,17 +1291,19 @@ sd_init_onedisk(struct scsi_disk * sdkp, struct gendisk *disk) ...@@ -1327,17 +1291,19 @@ sd_init_onedisk(struct scsi_disk * sdkp, struct gendisk *disk)
* and minor number that is chosen here. * and minor number that is chosen here.
* *
* Assume sd_attach is not re-entrant (for time being) * Assume sd_attach is not re-entrant (for time being)
* Also think about sd_attach() and sd_detach() running coincidentally. * Also think about sd_attach() and sd_remove() running coincidentally.
**/ **/
static int sd_attach(struct scsi_device * sdp) static int sd_probe(struct device *dev)
{ {
struct scsi_device *sdp = to_scsi_device(dev);
struct scsi_disk *sdkp; struct scsi_disk *sdkp;
struct gendisk *gd; struct gendisk *gd;
u32 index; u32 index;
int error; int error;
error = -ENODEV;
if ((sdp->type != TYPE_DISK) && (sdp->type != TYPE_MOD)) if ((sdp->type != TYPE_DISK) && (sdp->type != TYPE_MOD))
return 1; goto out;
SCSI_LOG_HLQUEUE(3, printk("sd_attach: scsi device: <%d,%d,%d,%d>\n", SCSI_LOG_HLQUEUE(3, printk("sd_attach: scsi device: <%d,%d,%d,%d>\n",
sdp->host->host_no, sdp->channel, sdp->id, sdp->lun)); sdp->host->host_no, sdp->channel, sdp->id, sdp->lun));
...@@ -1389,8 +1355,8 @@ static int sd_attach(struct scsi_device * sdp) ...@@ -1389,8 +1355,8 @@ static int sd_attach(struct scsi_device * sdp)
gd->private_data = &sdkp->driver; gd->private_data = &sdkp->driver;
gd->queue = sdkp->device->request_queue; gd->queue = sdkp->device->request_queue;
sd_devlist_insert(sdkp);
set_capacity(gd, sdkp->capacity); set_capacity(gd, sdkp->capacity);
dev_set_drvdata(dev, sdkp);
add_disk(gd); add_disk(gd);
printk(KERN_NOTICE "Attached scsi %sdisk %s at scsi%d, channel %d, " printk(KERN_NOTICE "Attached scsi %sdisk %s at scsi%d, channel %d, "
...@@ -1409,44 +1375,42 @@ static int sd_attach(struct scsi_device * sdp) ...@@ -1409,44 +1375,42 @@ static int sd_attach(struct scsi_device * sdp)
} }
/** /**
* sd_detach - called whenever a scsi disk (previously recognized by * sd_remove - called whenever a scsi disk (previously recognized by
* sd_attach) is detached from the system. It is called (potentially * sd_probe) is detached from the system. It is called (potentially
* multiple times) during sd module unload. * multiple times) during sd module unload.
* @sdp: pointer to mid level scsi device object * @sdp: pointer to mid level scsi device object
* *
* Note: this function is invoked from the scsi mid-level. * Note: this function is invoked from the scsi mid-level.
* This function potentially frees up a device name (e.g. /dev/sdc) * This function potentially frees up a device name (e.g. /dev/sdc)
* that could be re-used by a subsequent sd_attach(). * that could be re-used by a subsequent sd_probe().
* This function is not called when the built-in sd driver is "exit-ed". * This function is not called when the built-in sd driver is "exit-ed".
**/ **/
static void sd_detach(struct scsi_device * sdp) static int sd_remove(struct device *dev)
{ {
struct scsi_disk *sdkp; struct scsi_disk *sdkp = dev_get_drvdata(dev);
SCSI_LOG_HLQUEUE(3, printk("sd_detach: <%d,%d,%d,%d>\n",
sdp->host->host_no, sdp->channel, sdp->id,
sdp->lun));
sdkp = sd_find_by_sdev(sdp);
if (!sdkp)
return;
/* check that we actually have a write back cache to synchronize */
if (sdkp->WCE) {
printk(KERN_NOTICE "Synchronizing SCSI cache: ");
sd_synchronize_cache(sdkp, 1);
printk("\n");
}
sd_devlist_remove(sdkp);
del_gendisk(sdkp->disk); del_gendisk(sdkp->disk);
spin_lock(&sd_index_lock); spin_lock(&sd_index_lock);
clear_bit(sdkp->index, sd_index_bits); clear_bit(sdkp->index, sd_index_bits);
spin_unlock(&sd_index_lock); spin_unlock(&sd_index_lock);
sd_shutdown(dev);
put_disk(sdkp->disk); put_disk(sdkp->disk);
kfree(sdkp); kfree(sdkp);
return 0;
}
static void sd_shutdown(struct device *dev)
{
struct scsi_disk *sdkp = dev_get_drvdata(dev);
if (sdkp->WCE) {
printk(KERN_NOTICE "Synchronizing SCSI cache: ");
sd_synchronize_cache(sdkp, 1);
printk("\n");
}
} }
/** /**
...@@ -1457,7 +1421,7 @@ static void sd_detach(struct scsi_device * sdp) ...@@ -1457,7 +1421,7 @@ static void sd_detach(struct scsi_device * sdp)
**/ **/
static int __init init_sd(void) static int __init init_sd(void)
{ {
int majors = 0, rc = -ENODEV, i; int majors = 0, i;
SCSI_LOG_HLQUEUE(3, printk("init_sd: sd driver entry point\n")); SCSI_LOG_HLQUEUE(3, printk("init_sd: sd driver entry point\n"));
...@@ -1468,11 +1432,7 @@ static int __init init_sd(void) ...@@ -1468,11 +1432,7 @@ static int __init init_sd(void)
if (!majors) if (!majors)
return -ENODEV; return -ENODEV;
rc = scsi_register_device(&sd_template); return scsi_register_driver(&sd_template.gendrv);
if (rc)
return rc;
register_reboot_notifier(&sd_notifier_block);
return rc;
} }
/** /**
...@@ -1486,37 +1446,11 @@ static void __exit exit_sd(void) ...@@ -1486,37 +1446,11 @@ static void __exit exit_sd(void)
SCSI_LOG_HLQUEUE(3, printk("exit_sd: exiting sd driver\n")); SCSI_LOG_HLQUEUE(3, printk("exit_sd: exiting sd driver\n"));
unregister_reboot_notifier(&sd_notifier_block); scsi_unregister_driver(&sd_template.gendrv);
scsi_unregister_device(&sd_template);
for (i = 0; i < SD_MAJORS; i++) for (i = 0; i < SD_MAJORS; i++)
unregister_blkdev(sd_major(i), "sd"); unregister_blkdev(sd_major(i), "sd");
} }
/*
* XXX: this function does not take sd_devlist_lock to synchronize
* access to sd_devlist. This should be safe as no other reboot
* notifier can access it.
*/
static int sd_notifier(struct notifier_block *n, unsigned long event, void *p)
{
if (event != SYS_RESTART &&
event != SYS_HALT &&
event != SYS_POWER_OFF)
return NOTIFY_DONE;
if (!list_empty(&sd_devlist)) {
struct scsi_disk *sdkp;
printk(KERN_NOTICE "Synchronizing SCSI caches: ");
list_for_each_entry(sdkp, &sd_devlist, list)
if (sdkp->WCE)
sd_synchronize_cache(sdkp, 1);
printk("\n");
}
return NOTIFY_OK;
}
/* send a SYNCHRONIZE CACHE instruction down to the device through the /* send a SYNCHRONIZE CACHE instruction down to the device through the
* normal SCSI command structure. Wait for the command to complete (must * normal SCSI command structure. Wait for the command to complete (must
* have user context) */ * have user context) */
......
...@@ -112,24 +112,17 @@ static int sg_allow_dio = SG_ALLOW_DIO_DEF; ...@@ -112,24 +112,17 @@ static int sg_allow_dio = SG_ALLOW_DIO_DEF;
#define SG_DEV_ARR_LUMP 6 /* amount to over allocate sg_dev_arr by */ #define SG_DEV_ARR_LUMP 6 /* amount to over allocate sg_dev_arr by */
static int sg_attach(Scsi_Device *); static int sg_add(struct class_device *);
static void sg_detach(Scsi_Device *); static void sg_remove(struct class_device *);
static Scsi_Request *dummy_cmdp; /* only used for sizeof */ static Scsi_Request *dummy_cmdp; /* only used for sizeof */
static rwlock_t sg_dev_arr_lock = RW_LOCK_UNLOCKED; /* Also used to lock static rwlock_t sg_dev_arr_lock = RW_LOCK_UNLOCKED; /* Also used to lock
file descriptor list for device */ file descriptor list for device */
static struct Scsi_Device_Template sg_template = { static struct class_interface sg_interface = {
.module = THIS_MODULE, .add = sg_add,
.list = LIST_HEAD_INIT(sg_template.list), .remove = sg_remove,
.name = "generic",
.scsi_type = 0xff,
.attach = sg_attach,
.detach = sg_detach,
.scsi_driverfs_driver = {
.name = "sg",
},
}; };
typedef struct sg_scatter_hold { /* holding area for scsi scatter gather info */ typedef struct sg_scatter_hold { /* holding area for scsi scatter gather info */
...@@ -180,15 +173,13 @@ typedef struct sg_fd { /* holds the state of a file descriptor */ ...@@ -180,15 +173,13 @@ typedef struct sg_fd { /* holds the state of a file descriptor */
} Sg_fd; } Sg_fd;
typedef struct sg_device { /* holds the state of each scsi generic device */ typedef struct sg_device { /* holds the state of each scsi generic device */
struct Scsi_Device_Template *driver; struct scsi_device *device;
Scsi_Device *device;
wait_queue_head_t o_excl_wait; /* queue open() when O_EXCL in use */ wait_queue_head_t o_excl_wait; /* queue open() when O_EXCL in use */
int sg_tablesize; /* adapter's max scatter-gather table size */ int sg_tablesize; /* adapter's max scatter-gather table size */
Sg_fd *headfp; /* first open fd belonging to this device */ Sg_fd *headfp; /* first open fd belonging to this device */
volatile char detached; /* 0->attached, 1->detached pending removal */ volatile char detached; /* 0->attached, 1->detached pending removal */
volatile char exclude; /* opened for exclusive access */ volatile char exclude; /* opened for exclusive access */
char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */ char sgdebug; /* 0->off, 1->sense, 9->dump dev, 10-> all devs */
struct device sg_driverfs_dev;
struct gendisk *disk; struct gendisk *disk;
} Sg_device; } Sg_device;
...@@ -1328,27 +1319,10 @@ static struct file_operations sg_fops = { ...@@ -1328,27 +1319,10 @@ static struct file_operations sg_fops = {
.fasync = sg_fasync, .fasync = sg_fasync,
}; };
/* Driverfs file support */
static ssize_t
sg_device_kdev_read(struct device *driverfs_dev, char *page)
{
Sg_device *sdp = list_entry(driverfs_dev, Sg_device, sg_driverfs_dev);
return sprintf(page, "%x\n", MKDEV(sdp->disk->major,
sdp->disk->first_minor));
}
static DEVICE_ATTR(kdev,S_IRUGO,sg_device_kdev_read,NULL);
static ssize_t
sg_device_type_read(struct device *driverfs_dev, char *page)
{
return sprintf(page, "CHR\n");
}
static DEVICE_ATTR(type,S_IRUGO,sg_device_type_read,NULL);
static int static int
sg_attach(Scsi_Device * scsidp) sg_add(struct class_device *cdev)
{ {
struct scsi_device *scsidp = to_scsi_device(cdev->dev);
struct gendisk *disk; struct gendisk *disk;
Sg_device *sdp = NULL; Sg_device *sdp = NULL;
unsigned long iflags; unsigned long iflags;
...@@ -1416,8 +1390,6 @@ sg_attach(Scsi_Device * scsidp) ...@@ -1416,8 +1390,6 @@ sg_attach(Scsi_Device * scsidp)
SCSI_LOG_TIMEOUT(3, printk("sg_attach: dev=%d \n", k)); SCSI_LOG_TIMEOUT(3, printk("sg_attach: dev=%d \n", k));
memset(sdp, 0, sizeof(*sdp)); memset(sdp, 0, sizeof(*sdp));
sdp->driver = &sg_template;
disk->private_data = &sdp->driver;
sprintf(disk->disk_name, "sg%d", k); sprintf(disk->disk_name, "sg%d", k);
disk->major = SCSI_GENERIC_MAJOR; disk->major = SCSI_GENERIC_MAJOR;
disk->first_minor = k; disk->first_minor = k;
...@@ -1430,40 +1402,20 @@ sg_attach(Scsi_Device * scsidp) ...@@ -1430,40 +1402,20 @@ sg_attach(Scsi_Device * scsidp)
sdp->detached = 0; sdp->detached = 0;
sdp->sg_tablesize = scsidp->host ? scsidp->host->sg_tablesize : 0; sdp->sg_tablesize = scsidp->host ? scsidp->host->sg_tablesize : 0;
memset(&sdp->sg_driverfs_dev, 0, sizeof (struct device));
snprintf(sdp->sg_driverfs_dev.bus_id, BUS_ID_SIZE, "%s:gen",
scsidp->sdev_driverfs_dev.bus_id);
snprintf(sdp->sg_driverfs_dev.name, DEVICE_NAME_SIZE, "%sgeneric",
scsidp->sdev_driverfs_dev.name);
sdp->sg_driverfs_dev.parent = &scsidp->sdev_driverfs_dev;
sdp->sg_driverfs_dev.bus = scsidp->sdev_driverfs_dev.bus;
sg_nr_dev++; sg_nr_dev++;
sg_dev_arr[k] = sdp; sg_dev_arr[k] = sdp;
write_unlock_irqrestore(&sg_dev_arr_lock, iflags); write_unlock_irqrestore(&sg_dev_arr_lock, iflags);
device_register(&sdp->sg_driverfs_dev);
device_create_file(&sdp->sg_driverfs_dev, &dev_attr_type);
device_create_file(&sdp->sg_driverfs_dev, &dev_attr_kdev);
devfs_mk_cdev(MKDEV(SCSI_GENERIC_MAJOR, k), devfs_mk_cdev(MKDEV(SCSI_GENERIC_MAJOR, k),
S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP, S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP,
"%s/generic", scsidp->devfs_name); "%s/generic", scsidp->devfs_name);
switch (scsidp->type) { printk(KERN_NOTICE
case TYPE_DISK: "Attached scsi generic sg%d at scsi%d, channel"
case TYPE_MOD: " %d, id %d, lun %d, type %d\n", k,
case TYPE_ROM: scsidp->host->host_no, scsidp->channel, scsidp->id,
case TYPE_WORM: scsidp->lun, scsidp->type);
case TYPE_TAPE:
break;
default:
printk(KERN_NOTICE
"Attached scsi generic sg%d at scsi%d, channel"
" %d, id %d, lun %d, type %d\n", k,
scsidp->host->host_no, scsidp->channel, scsidp->id,
scsidp->lun, scsidp->type);
}
return 0; return 0;
out: out:
...@@ -1472,8 +1424,9 @@ sg_attach(Scsi_Device * scsidp) ...@@ -1472,8 +1424,9 @@ sg_attach(Scsi_Device * scsidp)
} }
static void static void
sg_detach(Scsi_Device * scsidp) sg_remove(struct class_device *cdev)
{ {
struct scsi_device *scsidp = to_scsi_device(cdev->dev);
Sg_device *sdp = NULL; Sg_device *sdp = NULL;
unsigned long iflags; unsigned long iflags;
Sg_fd *sfp; Sg_fd *sfp;
...@@ -1524,9 +1477,6 @@ sg_detach(Scsi_Device * scsidp) ...@@ -1524,9 +1477,6 @@ sg_detach(Scsi_Device * scsidp)
if (sdp) { if (sdp) {
devfs_remove("%s/generic", scsidp->devfs_name); devfs_remove("%s/generic", scsidp->devfs_name);
device_remove_file(&sdp->sg_driverfs_dev, &dev_attr_type);
device_remove_file(&sdp->sg_driverfs_dev, &dev_attr_kdev);
device_unregister(&sdp->sg_driverfs_dev);
put_disk(sdp->disk); put_disk(sdp->disk);
sdp->disk = NULL; sdp->disk = NULL;
if (NULL == sdp->headfp) if (NULL == sdp->headfp)
...@@ -1550,64 +1500,6 @@ MODULE_LICENSE("GPL"); ...@@ -1550,64 +1500,6 @@ MODULE_LICENSE("GPL");
MODULE_PARM_DESC(def_reserved_size, "size of buffer reserved for each fd"); MODULE_PARM_DESC(def_reserved_size, "size of buffer reserved for each fd");
static ssize_t sg_allow_dio_show(struct device_driver * ddp, char * buf)
{
return snprintf(buf, PAGE_SIZE, "%d\n", sg_allow_dio);
}
static ssize_t sg_allow_dio_store(struct device_driver * ddp,
const char * buf, size_t count)
{
if (1 == sscanf(buf, "%d", &sg_allow_dio)) {
sg_allow_dio = sg_allow_dio ? 1 : 0;
return count;
}
return -EINVAL;
}
DRIVER_ATTR(allow_dio, S_IRUGO | S_IWUSR, sg_allow_dio_show,
sg_allow_dio_store)
static ssize_t sg_def_reserved_show(struct device_driver * ddp, char * buf)
{
return snprintf(buf, PAGE_SIZE, "%d\n", sg_big_buff);
}
static ssize_t sg_def_reserved_store(struct device_driver * ddp,
const char * buf, size_t count)
{
if (1 == sscanf(buf, "%d", &def_reserved_size)) {
if (def_reserved_size >= 0) {
sg_big_buff = def_reserved_size;
return count;
}
}
return -EINVAL;
}
DRIVER_ATTR(def_reserved_size, S_IRUGO | S_IWUSR, sg_def_reserved_show,
sg_def_reserved_store)
static ssize_t sg_version_show(struct device_driver * ddp, char * buf)
{
return snprintf(buf, PAGE_SIZE, "%s\n", sg_version_str);
}
DRIVER_ATTR(version, S_IRUGO, sg_version_show, NULL)
static void do_create_driverfs_files(void)
{
struct device_driver * driverfs = &sg_template.scsi_driverfs_driver;
driver_create_file(driverfs, &driver_attr_allow_dio);
driver_create_file(driverfs, &driver_attr_def_reserved_size);
driver_create_file(driverfs, &driver_attr_version);
}
static void do_remove_driverfs_files(void)
{
struct device_driver * driverfs = &sg_template.scsi_driverfs_driver;
driver_remove_file(driverfs, &driver_attr_version);
driver_remove_file(driverfs, &driver_attr_def_reserved_size);
driver_remove_file(driverfs, &driver_attr_allow_dio);
}
static int __init static int __init
init_sg(void) init_sg(void)
{ {
...@@ -1619,24 +1511,22 @@ init_sg(void) ...@@ -1619,24 +1511,22 @@ init_sg(void)
rc = register_chrdev(SCSI_GENERIC_MAJOR, "sg", &sg_fops); rc = register_chrdev(SCSI_GENERIC_MAJOR, "sg", &sg_fops);
if (rc) if (rc)
return rc; return rc;
rc = scsi_register_device(&sg_template); rc = scsi_register_interface(&sg_interface);
if (rc) if (rc)
return rc; return rc;
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
sg_proc_init(); sg_proc_init();
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
do_create_driverfs_files();
return 0; return 0;
} }
static void __exit static void __exit
exit_sg(void) exit_sg(void)
{ {
do_remove_driverfs_files();
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
sg_proc_cleanup(); sg_proc_cleanup();
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
scsi_unregister_device(&sg_template); scsi_unregister_interface(&sg_interface);
unregister_chrdev(SCSI_GENERIC_MAJOR, "sg"); unregister_chrdev(SCSI_GENERIC_MAJOR, "sg");
if (sg_dev_arr != NULL) { if (sg_dev_arr != NULL) {
vfree((char *) sg_dev_arr); vfree((char *) sg_dev_arr);
......
...@@ -67,26 +67,20 @@ MODULE_PARM(xa_test, "i"); /* see sr_ioctl.c */ ...@@ -67,26 +67,20 @@ MODULE_PARM(xa_test, "i"); /* see sr_ioctl.c */
CDC_PLAY_AUDIO|CDC_RESET|CDC_IOCTLS|CDC_DRIVE_STATUS| \ CDC_PLAY_AUDIO|CDC_RESET|CDC_IOCTLS|CDC_DRIVE_STATUS| \
CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_GENERIC_PACKET) CDC_CD_R|CDC_CD_RW|CDC_DVD|CDC_DVD_R|CDC_GENERIC_PACKET)
static int sr_attach(struct scsi_device *); static int sr_probe(struct device *);
static void sr_detach(struct scsi_device *); static int sr_remove(struct device *);
static int sr_init_command(struct scsi_cmnd *); static int sr_init_command(struct scsi_cmnd *);
static struct Scsi_Device_Template sr_template = { static struct scsi_driver sr_template = {
.module = THIS_MODULE, .owner = THIS_MODULE,
.list = LIST_HEAD_INIT(sr_template.list), .gendrv = {
.name = "cdrom", .name = "sr",
.scsi_type = TYPE_ROM, .probe = sr_probe,
.attach = sr_attach, .remove = sr_remove,
.detach = sr_detach,
.init_command = sr_init_command,
.scsi_driverfs_driver = {
.name = "sr",
}, },
.init_command = sr_init_command,
}; };
static LIST_HEAD(sr_devlist);
static spinlock_t sr_devlist_lock = SPIN_LOCK_UNLOCKED;
static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG]; static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
static spinlock_t sr_index_lock = SPIN_LOCK_UNLOCKED; static spinlock_t sr_index_lock = SPIN_LOCK_UNLOCKED;
...@@ -99,37 +93,6 @@ static void get_capabilities(struct scsi_cd *); ...@@ -99,37 +93,6 @@ static void get_capabilities(struct scsi_cd *);
static int sr_media_change(struct cdrom_device_info *, int); static int sr_media_change(struct cdrom_device_info *, int);
static int sr_packet(struct cdrom_device_info *, struct cdrom_generic_command *); static int sr_packet(struct cdrom_device_info *, struct cdrom_generic_command *);
static Scsi_CD *sr_find_by_sdev(Scsi_Device *sd)
{
struct list_head *p;
Scsi_CD *cd;
spin_lock(&sr_devlist_lock);
list_for_each(p, &sr_devlist) {
cd = list_entry(p, Scsi_CD, list);
if (cd->device == sd) {
spin_unlock(&sr_devlist_lock);
return cd;
}
}
spin_unlock(&sr_devlist_lock);
return NULL;
}
static inline void sr_devlist_insert(Scsi_CD *cd)
{
spin_lock(&sr_devlist_lock);
list_add(&cd->list, &sr_devlist);
spin_unlock(&sr_devlist_lock);
}
static inline void sr_devlist_remove(Scsi_CD *cd)
{
spin_lock(&sr_devlist_lock);
list_del(&cd->list);
spin_unlock(&sr_devlist_lock);
}
static struct cdrom_device_ops sr_dops = { static struct cdrom_device_ops sr_dops = {
.open = sr_open, .open = sr_open,
.release = sr_release, .release = sr_release,
...@@ -506,14 +469,16 @@ static void sr_release(struct cdrom_device_info *cdi) ...@@ -506,14 +469,16 @@ static void sr_release(struct cdrom_device_info *cdi)
scsi_device_put(cd->device); scsi_device_put(cd->device);
} }
static int sr_attach(struct scsi_device *sdev) static int sr_probe(struct device *dev)
{ {
struct scsi_device *sdev = to_scsi_device(dev);
struct gendisk *disk; struct gendisk *disk;
struct scsi_cd *cd; struct scsi_cd *cd;
int minor, error; int minor, error;
error = -ENODEV;
if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM) if (sdev->type != TYPE_ROM && sdev->type != TYPE_WORM)
return 1; goto fail;
error = -ENOMEM; error = -ENOMEM;
cd = kmalloc(sizeof(*cd), GFP_KERNEL); cd = kmalloc(sizeof(*cd), GFP_KERNEL);
...@@ -575,8 +540,8 @@ static int sr_attach(struct scsi_device *sdev) ...@@ -575,8 +540,8 @@ static int sr_attach(struct scsi_device *sdev)
disk->private_data = &cd->driver; disk->private_data = &cd->driver;
disk->queue = sdev->request_queue; disk->queue = sdev->request_queue;
dev_set_drvdata(dev, cd);
add_disk(disk); add_disk(disk);
sr_devlist_insert(cd);
printk(KERN_DEBUG printk(KERN_DEBUG
"Attached scsi CD-ROM %s at scsi%d, channel %d, id %d, lun %d\n", "Attached scsi CD-ROM %s at scsi%d, channel %d, id %d, lun %d\n",
...@@ -807,15 +772,10 @@ static int sr_packet(struct cdrom_device_info *cdi, ...@@ -807,15 +772,10 @@ static int sr_packet(struct cdrom_device_info *cdi,
return cgc->stat; return cgc->stat;
} }
static void sr_detach(struct scsi_device * SDp) static int sr_remove(struct device *dev)
{ {
struct scsi_cd *cd; struct scsi_cd *cd = dev_get_drvdata(dev);
cd = sr_find_by_sdev(SDp);
if (!cd)
return;
sr_devlist_remove(cd);
del_gendisk(cd->disk); del_gendisk(cd->disk);
spin_lock(&sr_index_lock); spin_lock(&sr_index_lock);
...@@ -825,6 +785,8 @@ static void sr_detach(struct scsi_device * SDp) ...@@ -825,6 +785,8 @@ static void sr_detach(struct scsi_device * SDp)
put_disk(cd->disk); put_disk(cd->disk);
unregister_cdrom(&cd->cdi); unregister_cdrom(&cd->cdi);
kfree(cd); kfree(cd);
return 0;
} }
static int __init init_sr(void) static int __init init_sr(void)
...@@ -834,12 +796,12 @@ static int __init init_sr(void) ...@@ -834,12 +796,12 @@ static int __init init_sr(void)
rc = register_blkdev(SCSI_CDROM_MAJOR, "sr"); rc = register_blkdev(SCSI_CDROM_MAJOR, "sr");
if (rc) if (rc)
return rc; return rc;
return scsi_register_device(&sr_template); return scsi_register_driver(&sr_template.gendrv);
} }
static void __exit exit_sr(void) static void __exit exit_sr(void)
{ {
scsi_unregister_device(&sr_template); scsi_unregister_driver(&sr_template.gendrv);
unregister_blkdev(SCSI_CDROM_MAJOR, "sr"); unregister_blkdev(SCSI_CDROM_MAJOR, "sr");
} }
......
...@@ -25,8 +25,7 @@ ...@@ -25,8 +25,7 @@
#define IOCTL_TIMEOUT 30*HZ #define IOCTL_TIMEOUT 30*HZ
typedef struct scsi_cd { typedef struct scsi_cd {
struct Scsi_Device_Template *driver; struct scsi_driver *driver;
struct list_head list;
unsigned capacity; /* size in blocks */ unsigned capacity; /* size in blocks */
Scsi_Device *device; Scsi_Device *device;
unsigned int vendor; /* vendor code, see sr_vendor.c */ unsigned int vendor; /* vendor code, see sr_vendor.c */
......
...@@ -170,22 +170,19 @@ static int sgl_map_user_pages(struct scatterlist *, const unsigned int, ...@@ -170,22 +170,19 @@ static int sgl_map_user_pages(struct scatterlist *, const unsigned int,
unsigned long, size_t, int); unsigned long, size_t, int);
static int sgl_unmap_user_pages(struct scatterlist *, const unsigned int, int); static int sgl_unmap_user_pages(struct scatterlist *, const unsigned int, int);
static int st_attach(Scsi_Device *); static int st_probe(struct device *);
static void st_detach(Scsi_Device *); static int st_remove(struct device *);
static void do_create_driverfs_files(void); static void do_create_driverfs_files(void);
static void do_remove_driverfs_files(void); static void do_remove_driverfs_files(void);
static struct Scsi_Device_Template st_template = { static struct scsi_driver st_template = {
.module = THIS_MODULE, .owner = THIS_MODULE,
.list = LIST_HEAD_INIT(st_template.list), .gendrv = {
.name = "tape", .name = "st",
.scsi_type = TYPE_TAPE, .probe = st_probe,
.attach = st_attach, .remove = st_remove,
.detach = st_detach,
.scsi_driverfs_driver = {
.name = "st",
}, },
}; };
...@@ -3704,8 +3701,9 @@ static struct file_operations st_fops = ...@@ -3704,8 +3701,9 @@ static struct file_operations st_fops =
.release = st_release, .release = st_release,
}; };
static int st_attach(Scsi_Device * SDp) static int st_probe(struct device *dev)
{ {
struct scsi_device *SDp = to_scsi_device(dev);
struct gendisk *disk; struct gendisk *disk;
Scsi_Tape *tpnt; Scsi_Tape *tpnt;
ST_mode *STm; ST_mode *STm;
...@@ -3716,13 +3714,13 @@ static int st_attach(Scsi_Device * SDp) ...@@ -3716,13 +3714,13 @@ static int st_attach(Scsi_Device * SDp)
u64 bounce_limit; u64 bounce_limit;
if (SDp->type != TYPE_TAPE) if (SDp->type != TYPE_TAPE)
return 1; return -ENODEV;
if ((stp = st_incompatible(SDp))) { if ((stp = st_incompatible(SDp))) {
printk(KERN_INFO printk(KERN_INFO
"st: Found incompatible tape at scsi%d, channel %d, id %d, lun %d\n", "st: Found incompatible tape at scsi%d, channel %d, id %d, lun %d\n",
SDp->host->host_no, SDp->channel, SDp->id, SDp->lun); SDp->host->host_no, SDp->channel, SDp->id, SDp->lun);
printk(KERN_INFO "st: The suggested driver is %s.\n", stp); printk(KERN_INFO "st: The suggested driver is %s.\n", stp);
return 1; return -ENODEV;
} }
i = SDp->host->sg_tablesize; i = SDp->host->sg_tablesize;
...@@ -3862,43 +3860,11 @@ static int st_attach(Scsi_Device * SDp) ...@@ -3862,43 +3860,11 @@ static int st_attach(Scsi_Device * SDp)
write_unlock(&st_dev_arr_lock); write_unlock(&st_dev_arr_lock);
for (mode = 0; mode < ST_NBR_MODES; ++mode) { for (mode = 0; mode < ST_NBR_MODES; ++mode) {
char name[8];
/* Rewind entry */ /* Rewind entry */
sprintf(name, "mt%s", st_formats[mode]);
sprintf(tpnt->driverfs_dev_r[mode].bus_id, "%s:%s",
SDp->sdev_driverfs_dev.bus_id, name);
sprintf(tpnt->driverfs_dev_r[mode].name, "%s%s",
SDp->sdev_driverfs_dev.name, name);
tpnt->driverfs_dev_r[mode].parent = &SDp->sdev_driverfs_dev;
tpnt->driverfs_dev_r[mode].bus = SDp->sdev_driverfs_dev.bus;
tpnt->driverfs_dev_r[mode].driver_data =
(void *)(long)__mkdev(SCSI_TAPE_MAJOR, dev_num + (mode << 5));
device_register(&tpnt->driverfs_dev_r[mode]);
device_create_file(&tpnt->driverfs_dev_r[mode],
&dev_attr_type);
device_create_file(&tpnt->driverfs_dev_r[mode], &dev_attr_kdev);
devfs_mk_cdev(MKDEV(SCSI_TAPE_MAJOR, dev_num + (mode << 5)), devfs_mk_cdev(MKDEV(SCSI_TAPE_MAJOR, dev_num + (mode << 5)),
S_IFCHR | S_IRUGO | S_IWUGO, S_IFCHR | S_IRUGO | S_IWUGO,
"%s/mt%s", SDp->devfs_name, st_formats[mode]); "%s/mt%s", SDp->devfs_name, st_formats[mode]);
/* No-rewind entry */ /* No-rewind entry */
sprintf (name, "mt%sn", st_formats[mode]);
sprintf(tpnt->driverfs_dev_n[mode].bus_id, "%s:%s",
SDp->sdev_driverfs_dev.bus_id, name);
sprintf(tpnt->driverfs_dev_n[mode].name, "%s%s",
SDp->sdev_driverfs_dev.name, name);
tpnt->driverfs_dev_n[mode].parent= &SDp->sdev_driverfs_dev;
tpnt->driverfs_dev_n[mode].bus = SDp->sdev_driverfs_dev.bus;
tpnt->driverfs_dev_n[mode].driver_data =
(void *)(long)__mkdev(SCSI_TAPE_MAJOR, dev_num + (mode << 5) + 128);
device_register(&tpnt->driverfs_dev_n[mode]);
device_create_file(&tpnt->driverfs_dev_n[mode],
&dev_attr_type);
device_create_file(&tpnt->driverfs_dev_n[mode],
&dev_attr_kdev);
devfs_mk_cdev(MKDEV(SCSI_TAPE_MAJOR, dev_num + (mode << 5) + 128), devfs_mk_cdev(MKDEV(SCSI_TAPE_MAJOR, dev_num + (mode << 5) + 128),
S_IFCHR | S_IRUGO | S_IWUGO, S_IFCHR | S_IRUGO | S_IWUGO,
"%s/mt%sn", SDp->devfs_name, st_formats[mode]); "%s/mt%sn", SDp->devfs_name, st_formats[mode]);
...@@ -3918,11 +3884,12 @@ static int st_attach(Scsi_Device * SDp) ...@@ -3918,11 +3884,12 @@ static int st_attach(Scsi_Device * SDp)
out_buffer_free: out_buffer_free:
kfree(buffer); kfree(buffer);
out: out:
return 1; return -ENODEV;
}; };
static void st_detach(Scsi_Device * SDp) static int st_remove(struct device *dev)
{ {
Scsi_Device *SDp = to_scsi_device(dev);
Scsi_Tape *tpnt; Scsi_Tape *tpnt;
int i, mode; int i, mode;
...@@ -3937,16 +3904,6 @@ static void st_detach(Scsi_Device * SDp) ...@@ -3937,16 +3904,6 @@ static void st_detach(Scsi_Device * SDp)
for (mode = 0; mode < ST_NBR_MODES; ++mode) { for (mode = 0; mode < ST_NBR_MODES; ++mode) {
devfs_remove("%s/mt%s", SDp->devfs_name, st_formats[mode]); devfs_remove("%s/mt%s", SDp->devfs_name, st_formats[mode]);
devfs_remove("%s/mt%sn", SDp->devfs_name, st_formats[mode]); devfs_remove("%s/mt%sn", SDp->devfs_name, st_formats[mode]);
device_remove_file(&tpnt->driverfs_dev_r[mode],
&dev_attr_type);
device_remove_file(&tpnt->driverfs_dev_r[mode],
&dev_attr_kdev);
device_unregister(&tpnt->driverfs_dev_r[mode]);
device_remove_file(&tpnt->driverfs_dev_n[mode],
&dev_attr_type);
device_remove_file(&tpnt->driverfs_dev_n[mode],
&dev_attr_kdev);
device_unregister(&tpnt->driverfs_dev_n[mode]);
} }
tpnt->device = NULL; tpnt->device = NULL;
...@@ -3957,12 +3914,12 @@ static void st_detach(Scsi_Device * SDp) ...@@ -3957,12 +3914,12 @@ static void st_detach(Scsi_Device * SDp)
} }
put_disk(tpnt->disk); put_disk(tpnt->disk);
kfree(tpnt); kfree(tpnt);
return; return 0;
} }
} }
write_unlock(&st_dev_arr_lock); write_unlock(&st_dev_arr_lock);
return; return 0;
} }
static int __init init_st(void) static int __init init_st(void)
...@@ -3974,7 +3931,7 @@ static int __init init_st(void) ...@@ -3974,7 +3931,7 @@ static int __init init_st(void)
verstr, st_fixed_buffer_size, st_max_sg_segs); verstr, st_fixed_buffer_size, st_max_sg_segs);
if (register_chrdev(SCSI_TAPE_MAJOR, "st", &st_fops) >= 0) { if (register_chrdev(SCSI_TAPE_MAJOR, "st", &st_fops) >= 0) {
if (scsi_register_device(&st_template) == 0) { if (scsi_register_driver(&st_template.gendrv) == 0) {
do_create_driverfs_files(); do_create_driverfs_files();
return 0; return 0;
} }
...@@ -3987,20 +3944,10 @@ static int __init init_st(void) ...@@ -3987,20 +3944,10 @@ static int __init init_st(void)
static void __exit exit_st(void) static void __exit exit_st(void)
{ {
int i;
do_remove_driverfs_files(); do_remove_driverfs_files();
scsi_unregister_device(&st_template); scsi_unregister_driver(&st_template.gendrv);
unregister_chrdev(SCSI_TAPE_MAJOR, "st"); unregister_chrdev(SCSI_TAPE_MAJOR, "st");
if (scsi_tapes != NULL) { kfree(scsi_tapes);
for (i=0; i < st_dev_max; ++i)
if (scsi_tapes[i]) {
printk(KERN_WARNING "st: scsi_tapes[] not "
"empty after scsi_unregister_device\n");
st_detach(scsi_tapes[i]->device);
}
kfree(scsi_tapes);
}
printk(KERN_INFO "st: Unloaded.\n"); printk(KERN_INFO "st: Unloaded.\n");
} }
...@@ -4035,7 +3982,7 @@ static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL); ...@@ -4035,7 +3982,7 @@ static DRIVER_ATTR(version, S_IRUGO, st_version_show, NULL);
static void do_create_driverfs_files(void) static void do_create_driverfs_files(void)
{ {
struct device_driver *driverfs = &st_template.scsi_driverfs_driver; struct device_driver *driverfs = &st_template.gendrv;
driver_create_file(driverfs, &driver_attr_try_direct_io); driver_create_file(driverfs, &driver_attr_try_direct_io);
driver_create_file(driverfs, &driver_attr_fixed_buffer_size); driver_create_file(driverfs, &driver_attr_fixed_buffer_size);
...@@ -4045,7 +3992,7 @@ static void do_create_driverfs_files(void) ...@@ -4045,7 +3992,7 @@ static void do_create_driverfs_files(void)
static void do_remove_driverfs_files(void) static void do_remove_driverfs_files(void)
{ {
struct device_driver *driverfs = &st_template.scsi_driverfs_driver; struct device_driver *driverfs = &st_template.gendrv;
driver_remove_file(driverfs, &driver_attr_version); driver_remove_file(driverfs, &driver_attr_version);
driver_remove_file(driverfs, &driver_attr_max_sg_segs); driver_remove_file(driverfs, &driver_attr_max_sg_segs);
......
...@@ -70,7 +70,7 @@ typedef struct { ...@@ -70,7 +70,7 @@ typedef struct {
/* The tape drive descriptor */ /* The tape drive descriptor */
typedef struct { typedef struct {
struct Scsi_Device_Template *driver; struct scsi_driver *driver;
Scsi_Device *device; Scsi_Device *device;
struct semaphore lock; /* For serialization */ struct semaphore lock; /* For serialization */
struct completion wait; /* For SCSI commands */ struct completion wait; /* For SCSI commands */
...@@ -103,8 +103,6 @@ typedef struct { ...@@ -103,8 +103,6 @@ typedef struct {
/* Mode characteristics */ /* Mode characteristics */
ST_mode modes[ST_NBR_MODES]; ST_mode modes[ST_NBR_MODES];
int current_mode; int current_mode;
struct device driverfs_dev_r[ST_NBR_MODES];
struct device driverfs_dev_n[ST_NBR_MODES];
/* Status variables */ /* Status variables */
int partition; int partition;
......
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