aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/scsi/scsi_error.c7
-rw-r--r--drivers/scsi/scsi_lib.c225
-rw-r--r--drivers/scsi/sd.c48
-rw-r--r--drivers/scsi/sr.c19
-rw-r--r--include/scsi/osd_protocol.h10
-rw-r--r--include/scsi/scsi_driver.h9
6 files changed, 127 insertions, 191 deletions
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index f17aa7aa7879..47a1ffc4c904 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -1029,6 +1029,7 @@ retry:
1029 rtn = NEEDS_RETRY; 1029 rtn = NEEDS_RETRY;
1030 } else { 1030 } else {
1031 timeleft = wait_for_completion_timeout(&done, timeout); 1031 timeleft = wait_for_completion_timeout(&done, timeout);
1032 rtn = SUCCESS;
1032 } 1033 }
1033 1034
1034 shost->eh_action = NULL; 1035 shost->eh_action = NULL;
@@ -2306,6 +2307,12 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
2306 } 2307 }
2307 2308
2308 scmd = scsi_get_command(dev, GFP_KERNEL); 2309 scmd = scsi_get_command(dev, GFP_KERNEL);
2310 if (!scmd) {
2311 rtn = FAILED;
2312 put_device(&dev->sdev_gendev);
2313 goto out_put_autopm_host;
2314 }
2315
2309 blk_rq_init(NULL, &req); 2316 blk_rq_init(NULL, &req);
2310 scmd->request = &req; 2317 scmd->request = &req;
2311 2318
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 9db097a28a74..9f841df6add8 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -512,68 +512,6 @@ void scsi_run_host_queues(struct Scsi_Host *shost)
512 scsi_run_queue(sdev->request_queue); 512 scsi_run_queue(sdev->request_queue);
513} 513}
514 514
515static void __scsi_release_buffers(struct scsi_cmnd *, int);
516
517/*
518 * Function: scsi_end_request()
519 *
520 * Purpose: Post-processing of completed commands (usually invoked at end
521 * of upper level post-processing and scsi_io_completion).
522 *
523 * Arguments: cmd - command that is complete.
524 * error - 0 if I/O indicates success, < 0 for I/O error.
525 * bytes - number of bytes of completed I/O
526 * requeue - indicates whether we should requeue leftovers.
527 *
528 * Lock status: Assumed that lock is not held upon entry.
529 *
530 * Returns: cmd if requeue required, NULL otherwise.
531 *
532 * Notes: This is called for block device requests in order to
533 * mark some number of sectors as complete.
534 *
535 * We are guaranteeing that the request queue will be goosed
536 * at some point during this call.
537 * Notes: If cmd was requeued, upon return it will be a stale pointer.
538 */
539static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int error,
540 int bytes, int requeue)
541{
542 struct request_queue *q = cmd->device->request_queue;
543 struct request *req = cmd->request;
544
545 /*
546 * If there are blocks left over at the end, set up the command
547 * to queue the remainder of them.
548 */
549 if (blk_end_request(req, error, bytes)) {
550 /* kill remainder if no retrys */
551 if (error && scsi_noretry_cmd(cmd))
552 blk_end_request_all(req, error);
553 else {
554 if (requeue) {
555 /*
556 * Bleah. Leftovers again. Stick the
557 * leftovers in the front of the
558 * queue, and goose the queue again.
559 */
560 scsi_release_buffers(cmd);
561 scsi_requeue_command(q, cmd);
562 cmd = NULL;
563 }
564 return cmd;
565 }
566 }
567
568 /*
569 * This will goose the queue request function at the end, so we don't
570 * need to worry about launching another command.
571 */
572 __scsi_release_buffers(cmd, 0);
573 scsi_next_command(cmd);
574 return NULL;
575}
576
577static inline unsigned int scsi_sgtable_index(unsigned short nents) 515static inline unsigned int scsi_sgtable_index(unsigned short nents)
578{ 516{
579 unsigned int index; 517 unsigned int index;
@@ -625,30 +563,10 @@ static void scsi_free_sgtable(struct scsi_data_buffer *sdb)
625 __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free); 563 __sg_free_table(&sdb->table, SCSI_MAX_SG_SEGMENTS, scsi_sg_free);
626} 564}
627 565
628static void __scsi_release_buffers(struct scsi_cmnd *cmd, int do_bidi_check)
629{
630
631 if (cmd->sdb.table.nents)
632 scsi_free_sgtable(&cmd->sdb);
633
634 memset(&cmd->sdb, 0, sizeof(cmd->sdb));
635
636 if (do_bidi_check && scsi_bidi_cmnd(cmd)) {
637 struct scsi_data_buffer *bidi_sdb =
638 cmd->request->next_rq->special;
639 scsi_free_sgtable(bidi_sdb);
640 kmem_cache_free(scsi_sdb_cache, bidi_sdb);
641 cmd->request->next_rq->special = NULL;
642 }
643
644 if (scsi_prot_sg_count(cmd))
645 scsi_free_sgtable(cmd->prot_sdb);
646}
647
648/* 566/*
649 * Function: scsi_release_buffers() 567 * Function: scsi_release_buffers()
650 * 568 *
651 * Purpose: Completion processing for block device I/O requests. 569 * Purpose: Free resources allocate for a scsi_command.
652 * 570 *
653 * Arguments: cmd - command that we are bailing. 571 * Arguments: cmd - command that we are bailing.
654 * 572 *
@@ -659,15 +577,29 @@ static void __scsi_release_buffers(struct scsi_cmnd *cmd, int do_bidi_check)
659 * Notes: In the event that an upper level driver rejects a 577 * Notes: In the event that an upper level driver rejects a
660 * command, we must release resources allocated during 578 * command, we must release resources allocated during
661 * the __init_io() function. Primarily this would involve 579 * the __init_io() function. Primarily this would involve
662 * the scatter-gather table, and potentially any bounce 580 * the scatter-gather table.
663 * buffers.
664 */ 581 */
665void scsi_release_buffers(struct scsi_cmnd *cmd) 582void scsi_release_buffers(struct scsi_cmnd *cmd)
666{ 583{
667 __scsi_release_buffers(cmd, 1); 584 if (cmd->sdb.table.nents)
585 scsi_free_sgtable(&cmd->sdb);
586
587 memset(&cmd->sdb, 0, sizeof(cmd->sdb));
588
589 if (scsi_prot_sg_count(cmd))
590 scsi_free_sgtable(cmd->prot_sdb);
668} 591}
669EXPORT_SYMBOL(scsi_release_buffers); 592EXPORT_SYMBOL(scsi_release_buffers);
670 593
594static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd)
595{
596 struct scsi_data_buffer *bidi_sdb = cmd->request->next_rq->special;
597
598 scsi_free_sgtable(bidi_sdb);
599 kmem_cache_free(scsi_sdb_cache, bidi_sdb);
600 cmd->request->next_rq->special = NULL;
601}
602
671/** 603/**
672 * __scsi_error_from_host_byte - translate SCSI error code into errno 604 * __scsi_error_from_host_byte - translate SCSI error code into errno
673 * @cmd: SCSI command (unused) 605 * @cmd: SCSI command (unused)
@@ -725,16 +657,9 @@ static int __scsi_error_from_host_byte(struct scsi_cmnd *cmd, int result)
725 * 657 *
726 * Returns: Nothing 658 * Returns: Nothing
727 * 659 *
728 * Notes: This function is matched in terms of capabilities to 660 * Notes: We will finish off the specified number of sectors. If we
729 * the function that created the scatter-gather list. 661 * are done, the command block will be released and the queue
730 * In other words, if there are no bounce buffers 662 * function will be goosed. If we are not done then we have to
731 * (the normal case for most drivers), we don't need
732 * the logic to deal with cleaning up afterwards.
733 *
734 * We must call scsi_end_request(). This will finish off
735 * the specified number of sectors. If we are done, the
736 * command block will be released and the queue function
737 * will be goosed. If we are not done then we have to
738 * figure out what to do next: 663 * figure out what to do next:
739 * 664 *
740 * a) We can call scsi_requeue_command(). The request 665 * a) We can call scsi_requeue_command(). The request
@@ -743,7 +668,7 @@ static int __scsi_error_from_host_byte(struct scsi_cmnd *cmd, int result)
743 * be used if we made forward progress, or if we want 668 * be used if we made forward progress, or if we want
744 * to switch from READ(10) to READ(6) for example. 669 * to switch from READ(10) to READ(6) for example.
745 * 670 *
746 * b) We can call scsi_queue_insert(). The request will 671 * b) We can call __scsi_queue_insert(). The request will
747 * be put back on the queue and retried using the same 672 * be put back on the queue and retried using the same
748 * command as before, possibly after a delay. 673 * command as before, possibly after a delay.
749 * 674 *
@@ -801,6 +726,8 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
801 req->next_rq->resid_len = scsi_in(cmd)->resid; 726 req->next_rq->resid_len = scsi_in(cmd)->resid;
802 727
803 scsi_release_buffers(cmd); 728 scsi_release_buffers(cmd);
729 scsi_release_bidi_buffers(cmd);
730
804 blk_end_request_all(req, 0); 731 blk_end_request_all(req, 0);
805 732
806 scsi_next_command(cmd); 733 scsi_next_command(cmd);
@@ -840,12 +767,25 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
840 } 767 }
841 768
842 /* 769 /*
843 * A number of bytes were successfully read. If there 770 * If we finished all bytes in the request we are done now.
844 * are leftovers and there is some kind of error
845 * (result != 0), retry the rest.
846 */ 771 */
847 if (scsi_end_request(cmd, error, good_bytes, result == 0) == NULL) 772 if (!blk_end_request(req, error, good_bytes))
848 return; 773 goto next_command;
774
775 /*
776 * Kill remainder if no retrys.
777 */
778 if (error && scsi_noretry_cmd(cmd)) {
779 blk_end_request_all(req, error);
780 goto next_command;
781 }
782
783 /*
784 * If there had been no error, but we have leftover bytes in the
785 * requeues just queue the command up again.
786 */
787 if (result == 0)
788 goto requeue;
849 789
850 error = __scsi_error_from_host_byte(cmd, result); 790 error = __scsi_error_from_host_byte(cmd, result);
851 791
@@ -973,7 +913,6 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
973 switch (action) { 913 switch (action) {
974 case ACTION_FAIL: 914 case ACTION_FAIL:
975 /* Give up and fail the remainder of the request */ 915 /* Give up and fail the remainder of the request */
976 scsi_release_buffers(cmd);
977 if (!(req->cmd_flags & REQ_QUIET)) { 916 if (!(req->cmd_flags & REQ_QUIET)) {
978 if (description) 917 if (description)
979 scmd_printk(KERN_INFO, cmd, "%s\n", 918 scmd_printk(KERN_INFO, cmd, "%s\n",
@@ -983,12 +922,11 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
983 scsi_print_sense("", cmd); 922 scsi_print_sense("", cmd);
984 scsi_print_command(cmd); 923 scsi_print_command(cmd);
985 } 924 }
986 if (blk_end_request_err(req, error)) 925 if (!blk_end_request_err(req, error))
987 scsi_requeue_command(q, cmd); 926 goto next_command;
988 else 927 /*FALLTHRU*/
989 scsi_next_command(cmd);
990 break;
991 case ACTION_REPREP: 928 case ACTION_REPREP:
929 requeue:
992 /* Unprep the request and put it back at the head of the queue. 930 /* Unprep the request and put it back at the head of the queue.
993 * A new command will be prepared and issued. 931 * A new command will be prepared and issued.
994 */ 932 */
@@ -1004,6 +942,11 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
1004 __scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY, 0); 942 __scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY, 0);
1005 break; 943 break;
1006 } 944 }
945 return;
946
947next_command:
948 scsi_release_buffers(cmd);
949 scsi_next_command(cmd);
1007} 950}
1008 951
1009static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb, 952static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,
@@ -1130,15 +1073,7 @@ static struct scsi_cmnd *scsi_get_cmd_from_req(struct scsi_device *sdev,
1130 1073
1131int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req) 1074int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
1132{ 1075{
1133 struct scsi_cmnd *cmd; 1076 struct scsi_cmnd *cmd = req->special;
1134 int ret = scsi_prep_state_check(sdev, req);
1135
1136 if (ret != BLKPREP_OK)
1137 return ret;
1138
1139 cmd = scsi_get_cmd_from_req(sdev, req);
1140 if (unlikely(!cmd))
1141 return BLKPREP_DEFER;
1142 1077
1143 /* 1078 /*
1144 * BLOCK_PC requests may transfer data, in which case they must 1079 * BLOCK_PC requests may transfer data, in which case they must
@@ -1182,15 +1117,11 @@ EXPORT_SYMBOL(scsi_setup_blk_pc_cmnd);
1182 */ 1117 */
1183int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req) 1118int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req)
1184{ 1119{
1185 struct scsi_cmnd *cmd; 1120 struct scsi_cmnd *cmd = req->special;
1186 int ret = scsi_prep_state_check(sdev, req);
1187
1188 if (ret != BLKPREP_OK)
1189 return ret;
1190 1121
1191 if (unlikely(sdev->scsi_dh_data && sdev->scsi_dh_data->scsi_dh 1122 if (unlikely(sdev->scsi_dh_data && sdev->scsi_dh_data->scsi_dh
1192 && sdev->scsi_dh_data->scsi_dh->prep_fn)) { 1123 && sdev->scsi_dh_data->scsi_dh->prep_fn)) {
1193 ret = sdev->scsi_dh_data->scsi_dh->prep_fn(sdev, req); 1124 int ret = sdev->scsi_dh_data->scsi_dh->prep_fn(sdev, req);
1194 if (ret != BLKPREP_OK) 1125 if (ret != BLKPREP_OK)
1195 return ret; 1126 return ret;
1196 } 1127 }
@@ -1200,16 +1131,13 @@ int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req)
1200 */ 1131 */
1201 BUG_ON(!req->nr_phys_segments); 1132 BUG_ON(!req->nr_phys_segments);
1202 1133
1203 cmd = scsi_get_cmd_from_req(sdev, req);
1204 if (unlikely(!cmd))
1205 return BLKPREP_DEFER;
1206
1207 memset(cmd->cmnd, 0, BLK_MAX_CDB); 1134 memset(cmd->cmnd, 0, BLK_MAX_CDB);
1208 return scsi_init_io(cmd, GFP_ATOMIC); 1135 return scsi_init_io(cmd, GFP_ATOMIC);
1209} 1136}
1210EXPORT_SYMBOL(scsi_setup_fs_cmnd); 1137EXPORT_SYMBOL(scsi_setup_fs_cmnd);
1211 1138
1212int scsi_prep_state_check(struct scsi_device *sdev, struct request *req) 1139static int
1140scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
1213{ 1141{
1214 int ret = BLKPREP_OK; 1142 int ret = BLKPREP_OK;
1215 1143
@@ -1261,9 +1189,9 @@ int scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
1261 } 1189 }
1262 return ret; 1190 return ret;
1263} 1191}
1264EXPORT_SYMBOL(scsi_prep_state_check);
1265 1192
1266int scsi_prep_return(struct request_queue *q, struct request *req, int ret) 1193static int
1194scsi_prep_return(struct request_queue *q, struct request *req, int ret)
1267{ 1195{
1268 struct scsi_device *sdev = q->queuedata; 1196 struct scsi_device *sdev = q->queuedata;
1269 1197
@@ -1294,18 +1222,44 @@ int scsi_prep_return(struct request_queue *q, struct request *req, int ret)
1294 1222
1295 return ret; 1223 return ret;
1296} 1224}
1297EXPORT_SYMBOL(scsi_prep_return);
1298 1225
1299int scsi_prep_fn(struct request_queue *q, struct request *req) 1226static int scsi_prep_fn(struct request_queue *q, struct request *req)
1300{ 1227{
1301 struct scsi_device *sdev = q->queuedata; 1228 struct scsi_device *sdev = q->queuedata;
1302 int ret = BLKPREP_KILL; 1229 struct scsi_cmnd *cmd;
1230 int ret;
1303 1231
1304 if (req->cmd_type == REQ_TYPE_BLOCK_PC) 1232 ret = scsi_prep_state_check(sdev, req);
1233 if (ret != BLKPREP_OK)
1234 goto out;
1235
1236 cmd = scsi_get_cmd_from_req(sdev, req);
1237 if (unlikely(!cmd)) {
1238 ret = BLKPREP_DEFER;
1239 goto out;
1240 }
1241
1242 if (req->cmd_type == REQ_TYPE_FS)
1243 ret = scsi_cmd_to_driver(cmd)->init_command(cmd);
1244 else if (req->cmd_type == REQ_TYPE_BLOCK_PC)
1305 ret = scsi_setup_blk_pc_cmnd(sdev, req); 1245 ret = scsi_setup_blk_pc_cmnd(sdev, req);
1246 else
1247 ret = BLKPREP_KILL;
1248
1249out:
1306 return scsi_prep_return(q, req, ret); 1250 return scsi_prep_return(q, req, ret);
1307} 1251}
1308EXPORT_SYMBOL(scsi_prep_fn); 1252
1253static void scsi_unprep_fn(struct request_queue *q, struct request *req)
1254{
1255 if (req->cmd_type == REQ_TYPE_FS) {
1256 struct scsi_cmnd *cmd = req->special;
1257 struct scsi_driver *drv = scsi_cmd_to_driver(cmd);
1258
1259 if (drv->uninit_command)
1260 drv->uninit_command(cmd);
1261 }
1262}
1309 1263
1310/* 1264/*
1311 * scsi_dev_queue_ready: if we can send requests to sdev, return 1 else 1265 * scsi_dev_queue_ready: if we can send requests to sdev, return 1 else
@@ -1726,6 +1680,7 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
1726 return NULL; 1680 return NULL;
1727 1681
1728 blk_queue_prep_rq(q, scsi_prep_fn); 1682 blk_queue_prep_rq(q, scsi_prep_fn);
1683 blk_queue_unprep_rq(q, scsi_unprep_fn);
1729 blk_queue_softirq_done(q, scsi_softirq_done); 1684 blk_queue_softirq_done(q, scsi_softirq_done);
1730 blk_queue_rq_timed_out(q, scsi_times_out); 1685 blk_queue_rq_timed_out(q, scsi_times_out);
1731 blk_queue_lld_busy(q, scsi_lld_busy); 1686 blk_queue_lld_busy(q, scsi_lld_busy);
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index efcbcd182863..321faf603035 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -109,6 +109,8 @@ static int sd_suspend_system(struct device *);
109static int sd_suspend_runtime(struct device *); 109static int sd_suspend_runtime(struct device *);
110static int sd_resume(struct device *); 110static int sd_resume(struct device *);
111static void sd_rescan(struct device *); 111static void sd_rescan(struct device *);
112static int sd_init_command(struct scsi_cmnd *SCpnt);
113static void sd_uninit_command(struct scsi_cmnd *SCpnt);
112static int sd_done(struct scsi_cmnd *); 114static int sd_done(struct scsi_cmnd *);
113static int sd_eh_action(struct scsi_cmnd *, int); 115static int sd_eh_action(struct scsi_cmnd *, int);
114static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer); 116static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer);
@@ -503,6 +505,8 @@ static struct scsi_driver sd_template = {
503 .pm = &sd_pm_ops, 505 .pm = &sd_pm_ops,
504 }, 506 },
505 .rescan = sd_rescan, 507 .rescan = sd_rescan,
508 .init_command = sd_init_command,
509 .uninit_command = sd_uninit_command,
506 .done = sd_done, 510 .done = sd_done,
507 .eh_action = sd_eh_action, 511 .eh_action = sd_eh_action,
508}; 512};
@@ -838,9 +842,9 @@ static int scsi_setup_flush_cmnd(struct scsi_device *sdp, struct request *rq)
838 return scsi_setup_blk_pc_cmnd(sdp, rq); 842 return scsi_setup_blk_pc_cmnd(sdp, rq);
839} 843}
840 844
841static void sd_unprep_fn(struct request_queue *q, struct request *rq) 845static void sd_uninit_command(struct scsi_cmnd *SCpnt)
842{ 846{
843 struct scsi_cmnd *SCpnt = rq->special; 847 struct request *rq = SCpnt->request;
844 848
845 if (rq->cmd_flags & REQ_DISCARD) { 849 if (rq->cmd_flags & REQ_DISCARD) {
846 free_page((unsigned long)rq->buffer); 850 free_page((unsigned long)rq->buffer);
@@ -853,18 +857,10 @@ static void sd_unprep_fn(struct request_queue *q, struct request *rq)
853 } 857 }
854} 858}
855 859
856/** 860static int sd_init_command(struct scsi_cmnd *SCpnt)
857 * sd_prep_fn - build a scsi (read or write) command from
858 * information in the request structure.
859 * @SCpnt: pointer to mid-level's per scsi command structure that
860 * contains request and into which the scsi command is written
861 *
862 * Returns 1 if successful and 0 if error (or cannot be done now).
863 **/
864static int sd_prep_fn(struct request_queue *q, struct request *rq)
865{ 861{
866 struct scsi_cmnd *SCpnt; 862 struct request *rq = SCpnt->request;
867 struct scsi_device *sdp = q->queuedata; 863 struct scsi_device *sdp = SCpnt->device;
868 struct gendisk *disk = rq->rq_disk; 864 struct gendisk *disk = rq->rq_disk;
869 struct scsi_disk *sdkp; 865 struct scsi_disk *sdkp;
870 sector_t block = blk_rq_pos(rq); 866 sector_t block = blk_rq_pos(rq);
@@ -886,12 +882,6 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
886 } else if (rq->cmd_flags & REQ_FLUSH) { 882 } else if (rq->cmd_flags & REQ_FLUSH) {
887 ret = scsi_setup_flush_cmnd(sdp, rq); 883 ret = scsi_setup_flush_cmnd(sdp, rq);
888 goto out; 884 goto out;
889 } else if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
890 ret = scsi_setup_blk_pc_cmnd(sdp, rq);
891 goto out;
892 } else if (rq->cmd_type != REQ_TYPE_FS) {
893 ret = BLKPREP_KILL;
894 goto out;
895 } 885 }
896 ret = scsi_setup_fs_cmnd(sdp, rq); 886 ret = scsi_setup_fs_cmnd(sdp, rq);
897 if (ret != BLKPREP_OK) 887 if (ret != BLKPREP_OK)
@@ -903,11 +893,10 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
903 * is used for a killable error condition */ 893 * is used for a killable error condition */
904 ret = BLKPREP_KILL; 894 ret = BLKPREP_KILL;
905 895
906 SCSI_LOG_HLQUEUE(1, scmd_printk(KERN_INFO, SCpnt, 896 SCSI_LOG_HLQUEUE(1,
907 "sd_prep_fn: block=%llu, " 897 scmd_printk(KERN_INFO, SCpnt,
908 "count=%d\n", 898 "%s: block=%llu, count=%d\n",
909 (unsigned long long)block, 899 __func__, (unsigned long long)block, this_count));
910 this_count));
911 900
912 if (!sdp || !scsi_device_online(sdp) || 901 if (!sdp || !scsi_device_online(sdp) ||
913 block + blk_rq_sectors(rq) > get_capacity(disk)) { 902 block + blk_rq_sectors(rq) > get_capacity(disk)) {
@@ -1127,7 +1116,7 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
1127 */ 1116 */
1128 ret = BLKPREP_OK; 1117 ret = BLKPREP_OK;
1129 out: 1118 out:
1130 return scsi_prep_return(q, rq, ret); 1119 return ret;
1131} 1120}
1132 1121
1133/** 1122/**
@@ -1689,12 +1678,12 @@ static int sd_done(struct scsi_cmnd *SCpnt)
1689 sshdr.ascq)); 1678 sshdr.ascq));
1690 } 1679 }
1691#endif 1680#endif
1681 sdkp->medium_access_timed_out = 0;
1682
1692 if (driver_byte(result) != DRIVER_SENSE && 1683 if (driver_byte(result) != DRIVER_SENSE &&
1693 (!sense_valid || sense_deferred)) 1684 (!sense_valid || sense_deferred))
1694 goto out; 1685 goto out;
1695 1686
1696 sdkp->medium_access_timed_out = 0;
1697
1698 switch (sshdr.sense_key) { 1687 switch (sshdr.sense_key) {
1699 case HARDWARE_ERROR: 1688 case HARDWARE_ERROR:
1700 case MEDIUM_ERROR: 1689 case MEDIUM_ERROR:
@@ -2878,9 +2867,6 @@ static void sd_probe_async(void *data, async_cookie_t cookie)
2878 2867
2879 sd_revalidate_disk(gd); 2868 sd_revalidate_disk(gd);
2880 2869
2881 blk_queue_prep_rq(sdp->request_queue, sd_prep_fn);
2882 blk_queue_unprep_rq(sdp->request_queue, sd_unprep_fn);
2883
2884 gd->driverfs_dev = &sdp->sdev_gendev; 2870 gd->driverfs_dev = &sdp->sdev_gendev;
2885 gd->flags = GENHD_FL_EXT_DEVT; 2871 gd->flags = GENHD_FL_EXT_DEVT;
2886 if (sdp->removable) { 2872 if (sdp->removable) {
@@ -3028,8 +3014,6 @@ static int sd_remove(struct device *dev)
3028 3014
3029 async_synchronize_full_domain(&scsi_sd_pm_domain); 3015 async_synchronize_full_domain(&scsi_sd_pm_domain);
3030 async_synchronize_full_domain(&scsi_sd_probe_domain); 3016 async_synchronize_full_domain(&scsi_sd_probe_domain);
3031 blk_queue_prep_rq(sdkp->device->request_queue, scsi_prep_fn);
3032 blk_queue_unprep_rq(sdkp->device->request_queue, NULL);
3033 device_del(&sdkp->dev); 3017 device_del(&sdkp->dev);
3034 del_gendisk(sdkp->disk); 3018 del_gendisk(sdkp->disk);
3035 sd_shutdown(dev); 3019 sd_shutdown(dev);
diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c
index 40d85929aefe..93cbd36c990b 100644
--- a/drivers/scsi/sr.c
+++ b/drivers/scsi/sr.c
@@ -79,6 +79,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_WORM);
79static DEFINE_MUTEX(sr_mutex); 79static DEFINE_MUTEX(sr_mutex);
80static int sr_probe(struct device *); 80static int sr_probe(struct device *);
81static int sr_remove(struct device *); 81static int sr_remove(struct device *);
82static int sr_init_command(struct scsi_cmnd *SCpnt);
82static int sr_done(struct scsi_cmnd *); 83static int sr_done(struct scsi_cmnd *);
83static int sr_runtime_suspend(struct device *dev); 84static int sr_runtime_suspend(struct device *dev);
84 85
@@ -94,6 +95,7 @@ static struct scsi_driver sr_template = {
94 .remove = sr_remove, 95 .remove = sr_remove,
95 .pm = &sr_pm_ops, 96 .pm = &sr_pm_ops,
96 }, 97 },
98 .init_command = sr_init_command,
97 .done = sr_done, 99 .done = sr_done,
98}; 100};
99 101
@@ -378,21 +380,14 @@ static int sr_done(struct scsi_cmnd *SCpnt)
378 return good_bytes; 380 return good_bytes;
379} 381}
380 382
381static int sr_prep_fn(struct request_queue *q, struct request *rq) 383static int sr_init_command(struct scsi_cmnd *SCpnt)
382{ 384{
383 int block = 0, this_count, s_size; 385 int block = 0, this_count, s_size;
384 struct scsi_cd *cd; 386 struct scsi_cd *cd;
385 struct scsi_cmnd *SCpnt; 387 struct request *rq = SCpnt->request;
386 struct scsi_device *sdp = q->queuedata; 388 struct scsi_device *sdp = SCpnt->device;
387 int ret; 389 int ret;
388 390
389 if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
390 ret = scsi_setup_blk_pc_cmnd(sdp, rq);
391 goto out;
392 } else if (rq->cmd_type != REQ_TYPE_FS) {
393 ret = BLKPREP_KILL;
394 goto out;
395 }
396 ret = scsi_setup_fs_cmnd(sdp, rq); 391 ret = scsi_setup_fs_cmnd(sdp, rq);
397 if (ret != BLKPREP_OK) 392 if (ret != BLKPREP_OK)
398 goto out; 393 goto out;
@@ -517,7 +512,7 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
517 */ 512 */
518 ret = BLKPREP_OK; 513 ret = BLKPREP_OK;
519 out: 514 out:
520 return scsi_prep_return(q, rq, ret); 515 return ret;
521} 516}
522 517
523static int sr_block_open(struct block_device *bdev, fmode_t mode) 518static int sr_block_open(struct block_device *bdev, fmode_t mode)
@@ -718,7 +713,6 @@ static int sr_probe(struct device *dev)
718 713
719 /* FIXME: need to handle a get_capabilities failure properly ?? */ 714 /* FIXME: need to handle a get_capabilities failure properly ?? */
720 get_capabilities(cd); 715 get_capabilities(cd);
721 blk_queue_prep_rq(sdev->request_queue, sr_prep_fn);
722 sr_vendor_init(cd); 716 sr_vendor_init(cd);
723 717
724 disk->driverfs_dev = &sdev->sdev_gendev; 718 disk->driverfs_dev = &sdev->sdev_gendev;
@@ -993,7 +987,6 @@ static int sr_remove(struct device *dev)
993 987
994 scsi_autopm_get_device(cd->device); 988 scsi_autopm_get_device(cd->device);
995 989
996 blk_queue_prep_rq(cd->device->request_queue, scsi_prep_fn);
997 del_gendisk(cd->disk); 990 del_gendisk(cd->disk);
998 991
999 mutex_lock(&sr_ref_mutex); 992 mutex_lock(&sr_ref_mutex);
diff --git a/include/scsi/osd_protocol.h b/include/scsi/osd_protocol.h
index 25ac6283b9c7..a2594afe05c7 100644
--- a/include/scsi/osd_protocol.h
+++ b/include/scsi/osd_protocol.h
@@ -263,16 +263,16 @@ static inline struct osd_cdb_head *osd_cdb_head(struct osd_cdb *ocdb)
263 * Ex name = FORMAT_OSD we have OSD_ACT_FORMAT_OSD && OSDv1_ACT_FORMAT_OSD 263 * Ex name = FORMAT_OSD we have OSD_ACT_FORMAT_OSD && OSDv1_ACT_FORMAT_OSD
264 */ 264 */
265#define OSD_ACT___(Name, Num) \ 265#define OSD_ACT___(Name, Num) \
266 OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num), \ 266 OSD_ACT_##Name = cpu_to_be16(0x8880 + Num), \
267 OSDv1_ACT_##Name = __constant_cpu_to_be16(0x8800 + Num), 267 OSDv1_ACT_##Name = cpu_to_be16(0x8800 + Num),
268 268
269/* V2 only actions */ 269/* V2 only actions */
270#define OSD_ACT_V2(Name, Num) \ 270#define OSD_ACT_V2(Name, Num) \
271 OSD_ACT_##Name = __constant_cpu_to_be16(0x8880 + Num), 271 OSD_ACT_##Name = cpu_to_be16(0x8880 + Num),
272 272
273#define OSD_ACT_V1_V2(Name, Num1, Num2) \ 273#define OSD_ACT_V1_V2(Name, Num1, Num2) \
274 OSD_ACT_##Name = __constant_cpu_to_be16(Num2), \ 274 OSD_ACT_##Name = cpu_to_be16(Num2), \
275 OSDv1_ACT_##Name = __constant_cpu_to_be16(Num1), 275 OSDv1_ACT_##Name = cpu_to_be16(Num1),
276 276
277enum osd_service_actions { 277enum osd_service_actions {
278 OSD_ACT_V2(OBJECT_STRUCTURE_CHECK, 0x00) 278 OSD_ACT_V2(OBJECT_STRUCTURE_CHECK, 0x00)
diff --git a/include/scsi/scsi_driver.h b/include/scsi/scsi_driver.h
index 20fdfc2526ad..36c4114ed9bc 100644
--- a/include/scsi/scsi_driver.h
+++ b/include/scsi/scsi_driver.h
@@ -4,17 +4,17 @@
4#include <linux/device.h> 4#include <linux/device.h>
5 5
6struct module; 6struct module;
7struct request;
7struct scsi_cmnd; 8struct scsi_cmnd;
8struct scsi_device; 9struct scsi_device;
9struct request;
10struct request_queue;
11
12 10
13struct scsi_driver { 11struct scsi_driver {
14 struct module *owner; 12 struct module *owner;
15 struct device_driver gendrv; 13 struct device_driver gendrv;
16 14
17 void (*rescan)(struct device *); 15 void (*rescan)(struct device *);
16 int (*init_command)(struct scsi_cmnd *);
17 void (*uninit_command)(struct scsi_cmnd *);
18 int (*done)(struct scsi_cmnd *); 18 int (*done)(struct scsi_cmnd *);
19 int (*eh_action)(struct scsi_cmnd *, int); 19 int (*eh_action)(struct scsi_cmnd *, int);
20}; 20};
@@ -31,8 +31,5 @@ extern int scsi_register_interface(struct class_interface *);
31 31
32int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req); 32int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req);
33int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req); 33int scsi_setup_fs_cmnd(struct scsi_device *sdev, struct request *req);
34int scsi_prep_state_check(struct scsi_device *sdev, struct request *req);
35int scsi_prep_return(struct request_queue *q, struct request *req, int ret);
36int scsi_prep_fn(struct request_queue *, struct request *);
37 34
38#endif /* _SCSI_SCSI_DRIVER_H */ 35#endif /* _SCSI_SCSI_DRIVER_H */