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

This reverts commit 6f5391c283d7fdcf24bf40786ea79061919d1e1d ("[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-g9418d5d: 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: Ingo Molnar <mingo@elte.hu>
Acked-by: Matthew Wilcox <matthew@wil.cx>
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by Ingo Molnar and committed by Linus Torvalds ac40532e 158a9624

+58 -43
+3 -17
drivers/scsi/scsi.c
··· 59 #include <scsi/scsi_cmnd.h> 60 #include <scsi/scsi_dbg.h> 61 #include <scsi/scsi_device.h> 62 - #include <scsi/scsi_driver.h> 63 #include <scsi/scsi_eh.h> 64 #include <scsi/scsi_host.h> 65 #include <scsi/scsi_tcq.h> ··· 367 scsi_print_command(cmd); 368 if (level > 3) { 369 printk(KERN_INFO "buffer = 0x%p, bufflen = %d," 370 - " queuecommand 0x%p\n", 371 scsi_sglist(cmd), scsi_bufflen(cmd), 372 cmd->device->host->hostt->queuecommand); 373 374 } ··· 654 blk_complete_request(rq); 655 } 656 657 - /* Move this to a header if it becomes more generally useful */ 658 - static struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd) 659 - { 660 - return *(struct scsi_driver **)cmd->request->rq_disk->private_data; 661 - } 662 - 663 /* 664 * Function: scsi_finish_command 665 * ··· 665 { 666 struct scsi_device *sdev = cmd->device; 667 struct Scsi_Host *shost = sdev->host; 668 - struct scsi_driver *drv; 669 - unsigned int good_bytes; 670 671 scsi_device_unbusy(sdev); 672 ··· 690 "Notifying upper driver of completion " 691 "(result %x)\n", cmd->result)); 692 693 - good_bytes = cmd->request_bufflen; 694 - if (cmd->request->cmd_type != REQ_TYPE_BLOCK_PC) { 695 - drv = scsi_cmd_to_driver(cmd); 696 - if (drv->done) 697 - good_bytes = drv->done(cmd); 698 - } 699 - scsi_io_completion(cmd, good_bytes); 700 } 701 EXPORT_SYMBOL(scsi_finish_command); 702
··· 59 #include <scsi/scsi_cmnd.h> 60 #include <scsi/scsi_dbg.h> 61 #include <scsi/scsi_device.h> 62 #include <scsi/scsi_eh.h> 63 #include <scsi/scsi_host.h> 64 #include <scsi/scsi_tcq.h> ··· 368 scsi_print_command(cmd); 369 if (level > 3) { 370 printk(KERN_INFO "buffer = 0x%p, bufflen = %d," 371 + " done = 0x%p, queuecommand 0x%p\n", 372 scsi_sglist(cmd), scsi_bufflen(cmd), 373 + cmd->done, 374 cmd->device->host->hostt->queuecommand); 375 376 } ··· 654 blk_complete_request(rq); 655 } 656 657 /* 658 * Function: scsi_finish_command 659 * ··· 671 { 672 struct scsi_device *sdev = cmd->device; 673 struct Scsi_Host *shost = sdev->host; 674 675 scsi_device_unbusy(sdev); 676 ··· 698 "Notifying upper driver of completion " 699 "(result %x)\n", cmd->result)); 700 701 + cmd->done(cmd); 702 } 703 EXPORT_SYMBOL(scsi_finish_command); 704
+1
drivers/scsi/scsi_error.c
··· 1699 memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd)); 1700 1701 scmd->scsi_done = scsi_reset_provider_done_command; 1702 scmd->request_buffer = NULL; 1703 scmd->request_bufflen = 0; 1704
··· 1699 memset(&scmd->cmnd, '\0', sizeof(scmd->cmnd)); 1700 1701 scmd->scsi_done = scsi_reset_provider_done_command; 1702 + scmd->done = NULL; 1703 scmd->request_buffer = NULL; 1704 scmd->request_bufflen = 0; 1705
+14
drivers/scsi/scsi_lib.c
··· 1092 } 1093 scsi_end_request(cmd, 0, this_count, !result); 1094 } 1095 1096 /* 1097 * Function: scsi_init_io() ··· 1171 return cmd; 1172 } 1173 1174 int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req) 1175 { 1176 struct scsi_cmnd *cmd; ··· 1232 cmd->transfersize = req->data_len; 1233 cmd->allowed = req->retries; 1234 cmd->timeout_per_command = req->timeout; 1235 return BLKPREP_OK; 1236 } 1237 EXPORT_SYMBOL(scsi_setup_blk_pc_cmnd);
··· 1092 } 1093 scsi_end_request(cmd, 0, this_count, !result); 1094 } 1095 + EXPORT_SYMBOL(scsi_io_completion); 1096 1097 /* 1098 * Function: scsi_init_io() ··· 1170 return cmd; 1171 } 1172 1173 + static void scsi_blk_pc_done(struct scsi_cmnd *cmd) 1174 + { 1175 + BUG_ON(!blk_pc_request(cmd->request)); 1176 + /* 1177 + * This will complete the whole command with uptodate=1 so 1178 + * as far as the block layer is concerned the command completed 1179 + * successfully. Since this is a REQ_BLOCK_PC command the 1180 + * caller should check the request's errors value 1181 + */ 1182 + scsi_io_completion(cmd, cmd->request_bufflen); 1183 + } 1184 + 1185 int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req) 1186 { 1187 struct scsi_cmnd *cmd; ··· 1219 cmd->transfersize = req->data_len; 1220 cmd->allowed = req->retries; 1221 cmd->timeout_per_command = req->timeout; 1222 + cmd->done = scsi_blk_pc_done; 1223 return BLKPREP_OK; 1224 } 1225 EXPORT_SYMBOL(scsi_setup_blk_pc_cmnd);
-1
drivers/scsi/scsi_priv.h
··· 68 extern void scsi_device_unbusy(struct scsi_device *sdev); 69 extern int scsi_queue_insert(struct scsi_cmnd *cmd, int reason); 70 extern void scsi_next_command(struct scsi_cmnd *cmd); 71 - extern void scsi_io_completion(struct scsi_cmnd *, unsigned int); 72 extern void scsi_run_host_queues(struct Scsi_Host *shost); 73 extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev); 74 extern void scsi_free_queue(struct request_queue *q);
··· 68 extern void scsi_device_unbusy(struct scsi_device *sdev); 69 extern int scsi_queue_insert(struct scsi_cmnd *cmd, int reason); 70 extern void scsi_next_command(struct scsi_cmnd *cmd); 71 extern void scsi_run_host_queues(struct Scsi_Host *shost); 72 extern struct request_queue *scsi_alloc_queue(struct scsi_device *sdev); 73 extern void scsi_free_queue(struct request_queue *q);
+10 -18
drivers/scsi/sd.c
··· 86 MODULE_ALIAS_SCSI_DEVICE(TYPE_MOD); 87 MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC); 88 89 - static int sd_revalidate_disk(struct gendisk *); 90 - static int sd_probe(struct device *); 91 - static int sd_remove(struct device *); 92 - static void sd_shutdown(struct device *); 93 - static int sd_suspend(struct device *, pm_message_t state); 94 - static int sd_resume(struct device *); 95 - static void sd_rescan(struct device *); 96 - static int sd_done(struct scsi_cmnd *); 97 - static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer); 98 - static void scsi_disk_release(struct class_device *cdev); 99 - static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); 100 - static void sd_print_result(struct scsi_disk *, int); 101 - 102 static DEFINE_IDR(sd_index_idr); 103 static DEFINE_SPINLOCK(sd_index_lock); 104 ··· 240 .shutdown = sd_shutdown, 241 }, 242 .rescan = sd_rescan, 243 - .done = sd_done, 244 }; 245 246 /* ··· 507 SCpnt->underflow = this_count << 9; 508 SCpnt->allowed = SD_MAX_RETRIES; 509 SCpnt->timeout_per_command = timeout; 510 511 /* 512 * This indicates that the command is ready from our end to be ··· 887 }; 888 889 /** 890 - * sd_done - bottom half handler: called when the lower level 891 * driver has completed (successfully or otherwise) a scsi command. 892 * @SCpnt: mid-level's per command structure. 893 * 894 * Note: potentially run from within an ISR. Must not block. 895 **/ 896 - static int sd_done(struct scsi_cmnd *SCpnt) 897 { 898 int result = SCpnt->result; 899 unsigned int xfer_size = SCpnt->request_bufflen; ··· 914 SCSI_LOG_HLCOMPLETE(1, scsi_print_result(SCpnt)); 915 if (sense_valid) { 916 SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt, 917 - "sd_done: sb[respc,sk,asc," 918 "ascq]=%x,%x,%x,%x\n", 919 sshdr.response_code, 920 sshdr.sense_key, sshdr.asc, ··· 986 break; 987 } 988 out: 989 - return good_bytes; 990 } 991 992 static int media_not_present(struct scsi_disk *sdkp,
··· 86 MODULE_ALIAS_SCSI_DEVICE(TYPE_MOD); 87 MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC); 88 89 static DEFINE_IDR(sd_index_idr); 90 static DEFINE_SPINLOCK(sd_index_lock); 91 ··· 253 .shutdown = sd_shutdown, 254 }, 255 .rescan = sd_rescan, 256 }; 257 258 /* ··· 521 SCpnt->underflow = this_count << 9; 522 SCpnt->allowed = SD_MAX_RETRIES; 523 SCpnt->timeout_per_command = timeout; 524 + 525 + /* 526 + * This is the completion routine we use. This is matched in terms 527 + * of capability to this function. 528 + */ 529 + SCpnt->done = sd_rw_intr; 530 531 /* 532 * This indicates that the command is ready from our end to be ··· 895 }; 896 897 /** 898 + * sd_rw_intr - bottom half handler: called when the lower level 899 * driver has completed (successfully or otherwise) a scsi command. 900 * @SCpnt: mid-level's per command structure. 901 * 902 * Note: potentially run from within an ISR. Must not block. 903 **/ 904 + static void sd_rw_intr(struct scsi_cmnd * SCpnt) 905 { 906 int result = SCpnt->result; 907 unsigned int xfer_size = SCpnt->request_bufflen; ··· 922 SCSI_LOG_HLCOMPLETE(1, scsi_print_result(SCpnt)); 923 if (sense_valid) { 924 SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt, 925 + "sd_rw_intr: sb[respc,sk,asc," 926 "ascq]=%x,%x,%x,%x\n", 927 sshdr.response_code, 928 sshdr.sense_key, sshdr.asc, ··· 994 break; 995 } 996 out: 997 + scsi_io_completion(SCpnt, good_bytes); 998 } 999 1000 static int media_not_present(struct scsi_disk *sdkp,
+15 -6
drivers/scsi/sr.c
··· 78 79 static int sr_probe(struct device *); 80 static int sr_remove(struct device *); 81 - static int sr_done(struct scsi_cmnd *); 82 83 static struct scsi_driver sr_template = { 84 .owner = THIS_MODULE, ··· 86 .probe = sr_probe, 87 .remove = sr_remove, 88 }, 89 - .done = sr_done, 90 }; 91 92 static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG]; ··· 208 } 209 210 /* 211 - * sr_done is the interrupt routine for the device driver. 212 * 213 - * It will be notified on the end of a SCSI read / write, and will take one 214 * of several actions based on success or failure. 215 */ 216 - static int sr_done(struct scsi_cmnd *SCpnt) 217 { 218 int result = SCpnt->result; 219 int this_count = SCpnt->request_bufflen; ··· 286 } 287 } 288 289 - return good_bytes; 290 } 291 292 static int sr_prep_fn(struct request_queue *q, struct request *rq) ··· 426 SCpnt->underflow = this_count << 9; 427 SCpnt->allowed = MAX_RETRIES; 428 SCpnt->timeout_per_command = timeout; 429 430 /* 431 * This indicates that the command is ready from our end to be
··· 78 79 static int sr_probe(struct device *); 80 static int sr_remove(struct device *); 81 82 static struct scsi_driver sr_template = { 83 .owner = THIS_MODULE, ··· 87 .probe = sr_probe, 88 .remove = sr_remove, 89 }, 90 }; 91 92 static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG]; ··· 210 } 211 212 /* 213 + * rw_intr is the interrupt routine for the device driver. 214 * 215 + * It will be notified on the end of a SCSI read / write, and will take on 216 * of several actions based on success or failure. 217 */ 218 + static void rw_intr(struct scsi_cmnd * SCpnt) 219 { 220 int result = SCpnt->result; 221 int this_count = SCpnt->request_bufflen; ··· 288 } 289 } 290 291 + /* 292 + * This calls the generic completion function, now that we know 293 + * how many actual sectors finished, and how many sectors we need 294 + * to say have failed. 295 + */ 296 + scsi_io_completion(SCpnt, good_bytes); 297 } 298 299 static int sr_prep_fn(struct request_queue *q, struct request *rq) ··· 423 SCpnt->underflow = this_count << 9; 424 SCpnt->allowed = MAX_RETRIES; 425 SCpnt->timeout_per_command = timeout; 426 + 427 + /* 428 + * This is the completion routine we use. This is matched in terms 429 + * of capability to this function. 430 + */ 431 + SCpnt->done = rw_intr; 432 433 /* 434 * This indicates that the command is ready from our end to be
+2
include/scsi/scsi_cmnd.h
··· 34 struct list_head list; /* scsi_cmnd participates in queue lists */ 35 struct list_head eh_entry; /* entry for the host eh_cmd_q */ 36 int eh_eflags; /* Used by error handlr */ 37 38 /* 39 * A SCSI Command is assigned a nonzero serial_number before passed ··· 122 extern void scsi_put_command(struct scsi_cmnd *); 123 extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *, 124 struct device *); 125 extern void scsi_finish_command(struct scsi_cmnd *cmd); 126 extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd); 127
··· 34 struct list_head list; /* scsi_cmnd participates in queue lists */ 35 struct list_head eh_entry; /* entry for the host eh_cmd_q */ 36 int eh_eflags; /* Used by error handlr */ 37 + void (*done) (struct scsi_cmnd *); /* Mid-level done function */ 38 39 /* 40 * A SCSI Command is assigned a nonzero serial_number before passed ··· 121 extern void scsi_put_command(struct scsi_cmnd *); 122 extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *, 123 struct device *); 124 + extern void scsi_io_completion(struct scsi_cmnd *, unsigned int); 125 extern void scsi_finish_command(struct scsi_cmnd *cmd); 126 extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd); 127
-1
include/scsi/scsi_driver.h
··· 15 struct device_driver gendrv; 16 17 void (*rescan)(struct device *); 18 - int (*done)(struct scsi_cmnd *); 19 }; 20 #define to_scsi_driver(drv) \ 21 container_of((drv), struct scsi_driver, gendrv)
··· 15 struct device_driver gendrv; 16 17 void (*rescan)(struct device *); 18 }; 19 #define to_scsi_driver(drv) \ 20 container_of((drv), struct scsi_driver, gendrv)
+13
include/scsi/sd.h
··· 47 }; 48 #define to_scsi_disk(obj) container_of(obj,struct scsi_disk,cdev) 49 50 #define sd_printk(prefix, sdsk, fmt, a...) \ 51 (sdsk)->disk ? \ 52 sdev_printk(prefix, (sdsk)->device, "[%s] " fmt, \
··· 47 }; 48 #define to_scsi_disk(obj) container_of(obj,struct scsi_disk,cdev) 49 50 + static int sd_revalidate_disk(struct gendisk *disk); 51 + static void sd_rw_intr(struct scsi_cmnd * SCpnt); 52 + static int sd_probe(struct device *); 53 + static int sd_remove(struct device *); 54 + static void sd_shutdown(struct device *dev); 55 + static int sd_suspend(struct device *dev, pm_message_t state); 56 + static int sd_resume(struct device *dev); 57 + static void sd_rescan(struct device *); 58 + static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer); 59 + static void scsi_disk_release(struct class_device *cdev); 60 + static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); 61 + static void sd_print_result(struct scsi_disk *, int); 62 + 63 #define sd_printk(prefix, sdsk, fmt, a...) \ 64 (sdsk)->disk ? \ 65 sdev_printk(prefix, (sdsk)->device, "[%s] " fmt, \