Commit ac40532e authored by Ingo Molnar's avatar Ingo Molnar Committed by Linus Torvalds

scsi: revert "[SCSI] Get rid of scsi_cmnd->done"

This reverts commit 6f5391c2 ("[SCSI]
Get rid of scsi_cmnd->done") that was supposed to be a cleanup commit,
but apparently it causes regressions:

  Bug 9370 - v2.6.24-rc2-409-g9418d5dc: attempt to access beyond end of device
  http://bugzilla.kernel.org/show_bug.cgi?id=9370

this patch should be reintroduced in a more split-up form to make
testing of it easier.
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Acked-by: default avatarMatthew Wilcox <matthew@wil.cx>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 158a9624
...@@ -59,7 +59,6 @@ ...@@ -59,7 +59,6 @@
#include <scsi/scsi_cmnd.h> #include <scsi/scsi_cmnd.h>
#include <scsi/scsi_dbg.h> #include <scsi/scsi_dbg.h>
#include <scsi/scsi_device.h> #include <scsi/scsi_device.h>
#include <scsi/scsi_driver.h>
#include <scsi/scsi_eh.h> #include <scsi/scsi_eh.h>
#include <scsi/scsi_host.h> #include <scsi/scsi_host.h>
#include <scsi/scsi_tcq.h> #include <scsi/scsi_tcq.h>
...@@ -368,8 +367,9 @@ void scsi_log_send(struct scsi_cmnd *cmd) ...@@ -368,8 +367,9 @@ void scsi_log_send(struct scsi_cmnd *cmd)
scsi_print_command(cmd); scsi_print_command(cmd);
if (level > 3) { if (level > 3) {
printk(KERN_INFO "buffer = 0x%p, bufflen = %d," printk(KERN_INFO "buffer = 0x%p, bufflen = %d,"
" queuecommand 0x%p\n", " done = 0x%p, queuecommand 0x%p\n",
scsi_sglist(cmd), scsi_bufflen(cmd), scsi_sglist(cmd), scsi_bufflen(cmd),
cmd->done,
cmd->device->host->hostt->queuecommand); cmd->device->host->hostt->queuecommand);
} }
...@@ -654,12 +654,6 @@ void __scsi_done(struct scsi_cmnd *cmd) ...@@ -654,12 +654,6 @@ void __scsi_done(struct scsi_cmnd *cmd)
blk_complete_request(rq); blk_complete_request(rq);
} }
/* Move this to a header if it becomes more generally useful */
static struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)
{
return *(struct scsi_driver **)cmd->request->rq_disk->private_data;
}
/* /*
* Function: scsi_finish_command * Function: scsi_finish_command
* *
...@@ -671,8 +665,6 @@ void scsi_finish_command(struct scsi_cmnd *cmd) ...@@ -671,8 +665,6 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
{ {
struct scsi_device *sdev = cmd->device; struct scsi_device *sdev = cmd->device;
struct Scsi_Host *shost = sdev->host; struct Scsi_Host *shost = sdev->host;
struct scsi_driver *drv;
unsigned int good_bytes;
scsi_device_unbusy(sdev); scsi_device_unbusy(sdev);
...@@ -698,13 +690,7 @@ void scsi_finish_command(struct scsi_cmnd *cmd) ...@@ -698,13 +690,7 @@ void scsi_finish_command(struct scsi_cmnd *cmd)
"Notifying upper driver of completion " "Notifying upper driver of completion "
"(result %x)\n", cmd->result)); "(result %x)\n", cmd->result));
good_bytes = cmd->request_bufflen; cmd->done(cmd);
if (cmd->request->cmd_type != REQ_TYPE_BLOCK_PC) {
drv = scsi_cmd_to_driver(cmd);
if (drv->done)
good_bytes = drv->done(cmd);
}
scsi_io_completion(cmd, good_bytes);
} }
EXPORT_SYMBOL(scsi_finish_command); EXPORT_SYMBOL(scsi_finish_command);
......
...@@ -1699,6 +1699,7 @@ scsi_reset_provider(struct scsi_device *dev, int flag) ...@@ -1699,6 +1699,7 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd)); memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd));
scmd->scsi_done = scsi_reset_provider_done_command; scmd->scsi_done = scsi_reset_provider_done_command;
scmd->done = NULL;
scmd->request_buffer = NULL; scmd->request_buffer = NULL;
scmd->request_bufflen = 0; scmd->request_bufflen = 0;
......
...@@ -1092,6 +1092,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes) ...@@ -1092,6 +1092,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
} }
scsi_end_request(cmd, 0, this_count, !result); scsi_end_request(cmd, 0, this_count, !result);
} }
EXPORT_SYMBOL(scsi_io_completion);
/* /*
* Function: scsi_init_io() * Function: scsi_init_io()
...@@ -1170,6 +1171,18 @@ static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev, ...@@ -1170,6 +1171,18 @@ static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev,
return cmd; return cmd;
} }
static void scsi_blk_pc_done(struct scsi_cmnd *cmd)
{
BUG_ON(!blk_pc_request(cmd->request));
/*
* This will complete the whole command with uptodate=1 so
* as far as the block layer is concerned the command completed
* successfully. Since this is a REQ_BLOCK_PC command the
* caller should check the request's errors value
*/
scsi_io_completion(cmd, cmd->request_bufflen);
}
int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req) int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
{ {
struct scsi_cmnd *cmd; struct scsi_cmnd *cmd;
...@@ -1219,6 +1232,7 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req) ...@@ -1219,6 +1232,7 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
cmd->transfersize = req->data_len; cmd->transfersize = req->data_len;
cmd->allowed = req->retries; cmd->allowed = req->retries;
cmd->timeout_per_command = req->timeout; cmd->timeout_per_command = req->timeout;
cmd->done = scsi_blk_pc_done;
return BLKPREP_OK; return BLKPREP_OK;
} }
EXPORT_SYMBOL(scsi_setup_blk_pc_cmnd); EXPORT_SYMBOL(scsi_setup_blk_pc_cmnd);
......
...@@ -68,7 +68,6 @@ extern int scsi_maybe_unblock_host(struct scsi_device *sdev); ...@@ -68,7 +68,6 @@ extern int scsi_maybe_unblock_host(struct scsi_device *sdev);
extern void scsi_device_unbusy(struct scsi_device *sdev); extern void scsi_device_unbusy(struct scsi_device *sdev);
extern int scsi_queue_insert(struct scsi_cmnd *cmd, int reason); extern int scsi_queue_insert(struct scsi_cmnd *cmd, int reason);
extern void scsi_next_command(struct scsi_cmnd *cmd); extern void scsi_next_command(struct scsi_cmnd *cmd);
extern void scsi_io_completion(struct scsi_cmnd *, unsigned int);
extern void scsi_run_host_queues(struct Scsi_Host *shost); extern void scsi_run_host_queues(struct Scsi_Host *shost);
extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev); extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev);
extern void scsi_free_queue(struct request_queue *q); extern void scsi_free_queue(struct request_queue *q);
......
...@@ -86,19 +86,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_DISK); ...@@ -86,19 +86,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_DISK);
MODULE_ALIAS_SCSI_DEVICE(TYPE_MOD); MODULE_ALIAS_SCSI_DEVICE(TYPE_MOD);
MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC); MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC);
static int sd_revalidate_disk(struct gendisk *);
static int sd_probe(struct device *);
static int sd_remove(struct device *);
static void sd_shutdown(struct device *);
static int sd_suspend(struct device *, pm_message_t state);
static int sd_resume(struct device *);
static void sd_rescan(struct device *);
static int sd_done(struct scsi_cmnd *);
static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer);
static void scsi_disk_release(struct class_device *cdev);
static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
static void sd_print_result(struct scsi_disk *, int);
static DEFINE_IDR(sd_index_idr); static DEFINE_IDR(sd_index_idr);
static DEFINE_SPINLOCK(sd_index_lock); static DEFINE_SPINLOCK(sd_index_lock);
...@@ -253,7 +240,6 @@ static struct scsi_driver sd_template = { ...@@ -253,7 +240,6 @@ static struct scsi_driver sd_template = {
.shutdown = sd_shutdown, .shutdown = sd_shutdown,
}, },
.rescan = sd_rescan, .rescan = sd_rescan,
.done = sd_done,
}; };
/* /*
...@@ -522,6 +508,12 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq) ...@@ -522,6 +508,12 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
SCpnt->allowed = SD_MAX_RETRIES; SCpnt->allowed = SD_MAX_RETRIES;
SCpnt->timeout_per_command = timeout; SCpnt->timeout_per_command = timeout;
/*
* This is the completion routine we use. This is matched in terms
* of capability to this function.
*/
SCpnt->done = sd_rw_intr;
/* /*
* This indicates that the command is ready from our end to be * This indicates that the command is ready from our end to be
* queued. * queued.
...@@ -895,13 +887,13 @@ static struct block_device_operations sd_fops = { ...@@ -895,13 +887,13 @@ static struct block_device_operations sd_fops = {
}; };
/** /**
* sd_done - bottom half handler: called when the lower level * sd_rw_intr - bottom half handler: called when the lower level
* driver has completed (successfully or otherwise) a scsi command. * driver has completed (successfully or otherwise) a scsi command.
* @SCpnt: mid-level's per command structure. * @SCpnt: mid-level's per command structure.
* *
* Note: potentially run from within an ISR. Must not block. * Note: potentially run from within an ISR. Must not block.
**/ **/
static int sd_done(struct scsi_cmnd *SCpnt) static void sd_rw_intr(struct scsi_cmnd * SCpnt)
{ {
int result = SCpnt->result; int result = SCpnt->result;
unsigned int xfer_size = SCpnt->request_bufflen; unsigned int xfer_size = SCpnt->request_bufflen;
...@@ -922,7 +914,7 @@ static int sd_done(struct scsi_cmnd *SCpnt) ...@@ -922,7 +914,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
SCSI_LOG_HLCOMPLETE(1, scsi_print_result(SCpnt)); SCSI_LOG_HLCOMPLETE(1, scsi_print_result(SCpnt));
if (sense_valid) { if (sense_valid) {
SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt, SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt,
"sd_done: sb[respc,sk,asc," "sd_rw_intr: sb[respc,sk,asc,"
"ascq]=%x,%x,%x,%x\n", "ascq]=%x,%x,%x,%x\n",
sshdr.response_code, sshdr.response_code,
sshdr.sense_key, sshdr.asc, sshdr.sense_key, sshdr.asc,
...@@ -994,7 +986,7 @@ static int sd_done(struct scsi_cmnd *SCpnt) ...@@ -994,7 +986,7 @@ static int sd_done(struct scsi_cmnd *SCpnt)
break; break;
} }
out: out:
return good_bytes; scsi_io_completion(SCpnt, good_bytes);
} }
static int media_not_present(struct scsi_disk *sdkp, static int media_not_present(struct scsi_disk *sdkp,
......
...@@ -78,7 +78,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM); ...@@ -78,7 +78,6 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM);
static int sr_probe(struct device *); static int sr_probe(struct device *);
static int sr_remove(struct device *); static int sr_remove(struct device *);
static int sr_done(struct scsi_cmnd *);
static struct scsi_driver sr_template = { static struct scsi_driver sr_template = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -87,7 +86,6 @@ static struct scsi_driver sr_template = { ...@@ -87,7 +86,6 @@ static struct scsi_driver sr_template = {
.probe = sr_probe, .probe = sr_probe,
.remove = sr_remove, .remove = sr_remove,
}, },
.done = sr_done,
}; };
static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG]; static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG];
...@@ -210,12 +208,12 @@ static int sr_media_change(struct cdrom_device_info *cdi, int slot) ...@@ -210,12 +208,12 @@ static int sr_media_change(struct cdrom_device_info *cdi, int slot)
} }
/* /*
* sr_done is the interrupt routine for the device driver. * rw_intr is the interrupt routine for the device driver.
* *
* It will be notified on the end of a SCSI read / write, and will take one * It will be notified on the end of a SCSI read / write, and will take on
* of several actions based on success or failure. * of several actions based on success or failure.
*/ */
static int sr_done(struct scsi_cmnd *SCpnt) static void rw_intr(struct scsi_cmnd * SCpnt)
{ {
int result = SCpnt->result; int result = SCpnt->result;
int this_count = SCpnt->request_bufflen; int this_count = SCpnt->request_bufflen;
...@@ -288,7 +286,12 @@ static int sr_done(struct scsi_cmnd *SCpnt) ...@@ -288,7 +286,12 @@ static int sr_done(struct scsi_cmnd *SCpnt)
} }
} }
return good_bytes; /*
* This calls the generic completion function, now that we know
* how many actual sectors finished, and how many sectors we need
* to say have failed.
*/
scsi_io_completion(SCpnt, good_bytes);
} }
static int sr_prep_fn(struct request_queue *q, struct request *rq) static int sr_prep_fn(struct request_queue *q, struct request *rq)
...@@ -424,6 +427,12 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq) ...@@ -424,6 +427,12 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
SCpnt->allowed = MAX_RETRIES; SCpnt->allowed = MAX_RETRIES;
SCpnt->timeout_per_command = timeout; SCpnt->timeout_per_command = timeout;
/*
* This is the completion routine we use. This is matched in terms
* of capability to this function.
*/
SCpnt->done = rw_intr;
/* /*
* This indicates that the command is ready from our end to be * This indicates that the command is ready from our end to be
* queued. * queued.
......
...@@ -34,6 +34,7 @@ struct scsi_cmnd { ...@@ -34,6 +34,7 @@ struct scsi_cmnd {
struct list_head list; /* scsi_cmnd participates in queue lists */ struct list_head list; /* scsi_cmnd participates in queue lists */
struct list_head eh_entry; /* entry for the host eh_cmd_q */ struct list_head eh_entry; /* entry for the host eh_cmd_q */
int eh_eflags; /* Used by error handlr */ int eh_eflags; /* Used by error handlr */
void (*done) (struct scsi_cmnd *); /* Mid-level done function */
/* /*
* A SCSI Command is assigned a nonzero serial_number before passed * A SCSI Command is assigned a nonzero serial_number before passed
...@@ -121,6 +122,7 @@ extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t); ...@@ -121,6 +122,7 @@ extern struct scsi_cmnd *__scsi_get_command(struct Scsi_Host *, gfp_t);
extern void scsi_put_command(struct scsi_cmnd *); extern void scsi_put_command(struct scsi_cmnd *);
extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *, extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
struct device *); struct device *);
extern void scsi_io_completion(struct scsi_cmnd *, unsigned int);
extern void scsi_finish_command(struct scsi_cmnd *cmd); extern void scsi_finish_command(struct scsi_cmnd *cmd);
extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd); extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
......
...@@ -15,7 +15,6 @@ struct scsi_driver { ...@@ -15,7 +15,6 @@ struct scsi_driver {
struct device_driver gendrv; struct device_driver gendrv;
void (*rescan)(struct device *); void (*rescan)(struct device *);
int (*done)(struct scsi_cmnd *);
}; };
#define to_scsi_driver(drv) \ #define to_scsi_driver(drv) \
container_of((drv), struct scsi_driver, gendrv) container_of((drv), struct scsi_driver, gendrv)
......
...@@ -47,6 +47,19 @@ struct scsi_disk { ...@@ -47,6 +47,19 @@ struct scsi_disk {
}; };
#define to_scsi_disk(obj) container_of(obj,struct scsi_disk,cdev) #define to_scsi_disk(obj) container_of(obj,struct scsi_disk,cdev)
static int sd_revalidate_disk(struct gendisk *disk);
static void sd_rw_intr(struct scsi_cmnd * SCpnt);
static int sd_probe(struct device *);
static int sd_remove(struct device *);
static void sd_shutdown(struct device *dev);
static int sd_suspend(struct device *dev, pm_message_t state);
static int sd_resume(struct device *dev);
static void sd_rescan(struct device *);
static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer);
static void scsi_disk_release(struct class_device *cdev);
static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
static void sd_print_result(struct scsi_disk *, int);
#define sd_printk(prefix, sdsk, fmt, a...) \ #define sd_printk(prefix, sdsk, fmt, a...) \
(sdsk)->disk ? \ (sdsk)->disk ? \
sdev_printk(prefix, (sdsk)->device, "[%s] " fmt, \ sdev_printk(prefix, (sdsk)->device, "[%s] " fmt, \
......
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