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