diff options
Diffstat (limited to 'drivers/scsi/scsi_lib.c')
-rw-r--r-- | drivers/scsi/scsi_lib.c | 138 |
1 files changed, 88 insertions, 50 deletions
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 77f2d444f7e0..863bb6495daa 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c | |||
@@ -97,6 +97,30 @@ int scsi_insert_special_req(struct scsi_request *sreq, int at_head) | |||
97 | } | 97 | } |
98 | 98 | ||
99 | static void scsi_run_queue(struct request_queue *q); | 99 | static void scsi_run_queue(struct request_queue *q); |
100 | static void scsi_release_buffers(struct scsi_cmnd *cmd); | ||
101 | |||
102 | /* | ||
103 | * Function: scsi_unprep_request() | ||
104 | * | ||
105 | * Purpose: Remove all preparation done for a request, including its | ||
106 | * associated scsi_cmnd, so that it can be requeued. | ||
107 | * | ||
108 | * Arguments: req - request to unprepare | ||
109 | * | ||
110 | * Lock status: Assumed that no locks are held upon entry. | ||
111 | * | ||
112 | * Returns: Nothing. | ||
113 | */ | ||
114 | static void scsi_unprep_request(struct request *req) | ||
115 | { | ||
116 | struct scsi_cmnd *cmd = req->special; | ||
117 | |||
118 | req->flags &= ~REQ_DONTPREP; | ||
119 | req->special = (req->flags & REQ_SPECIAL) ? cmd->sc_request : NULL; | ||
120 | |||
121 | scsi_release_buffers(cmd); | ||
122 | scsi_put_command(cmd); | ||
123 | } | ||
100 | 124 | ||
101 | /* | 125 | /* |
102 | * Function: scsi_queue_insert() | 126 | * Function: scsi_queue_insert() |
@@ -116,12 +140,14 @@ static void scsi_run_queue(struct request_queue *q); | |||
116 | * commands. | 140 | * commands. |
117 | * Notes: This could be called either from an interrupt context or a | 141 | * Notes: This could be called either from an interrupt context or a |
118 | * normal process context. | 142 | * normal process context. |
143 | * Notes: Upon return, cmd is a stale pointer. | ||
119 | */ | 144 | */ |
120 | int scsi_queue_insert(struct scsi_cmnd *cmd, int reason) | 145 | int scsi_queue_insert(struct scsi_cmnd *cmd, int reason) |
121 | { | 146 | { |
122 | struct Scsi_Host *host = cmd->device->host; | 147 | struct Scsi_Host *host = cmd->device->host; |
123 | struct scsi_device *device = cmd->device; | 148 | struct scsi_device *device = cmd->device; |
124 | struct request_queue *q = device->request_queue; | 149 | struct request_queue *q = device->request_queue; |
150 | struct request *req = cmd->request; | ||
125 | unsigned long flags; | 151 | unsigned long flags; |
126 | 152 | ||
127 | SCSI_LOG_MLQUEUE(1, | 153 | SCSI_LOG_MLQUEUE(1, |
@@ -162,8 +188,9 @@ int scsi_queue_insert(struct scsi_cmnd *cmd, int reason) | |||
162 | * function. The SCSI request function detects the blocked condition | 188 | * function. The SCSI request function detects the blocked condition |
163 | * and plugs the queue appropriately. | 189 | * and plugs the queue appropriately. |
164 | */ | 190 | */ |
191 | scsi_unprep_request(req); | ||
165 | spin_lock_irqsave(q->queue_lock, flags); | 192 | spin_lock_irqsave(q->queue_lock, flags); |
166 | blk_requeue_request(q, cmd->request); | 193 | blk_requeue_request(q, req); |
167 | spin_unlock_irqrestore(q->queue_lock, flags); | 194 | spin_unlock_irqrestore(q->queue_lock, flags); |
168 | 195 | ||
169 | scsi_run_queue(q); | 196 | scsi_run_queue(q); |
@@ -339,7 +366,7 @@ int scsi_execute_req(struct scsi_device *sdev, const unsigned char *cmd, | |||
339 | int result; | 366 | int result; |
340 | 367 | ||
341 | if (sshdr) { | 368 | if (sshdr) { |
342 | sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_KERNEL); | 369 | sense = kmalloc(SCSI_SENSE_BUFFERSIZE, GFP_NOIO); |
343 | if (!sense) | 370 | if (!sense) |
344 | return DRIVER_ERROR << 24; | 371 | return DRIVER_ERROR << 24; |
345 | memset(sense, 0, SCSI_SENSE_BUFFERSIZE); | 372 | memset(sense, 0, SCSI_SENSE_BUFFERSIZE); |
@@ -552,15 +579,16 @@ static void scsi_run_queue(struct request_queue *q) | |||
552 | * I/O errors in the middle of the request, in which case | 579 | * I/O errors in the middle of the request, in which case |
553 | * we need to request the blocks that come after the bad | 580 | * we need to request the blocks that come after the bad |
554 | * sector. | 581 | * sector. |
582 | * Notes: Upon return, cmd is a stale pointer. | ||
555 | */ | 583 | */ |
556 | static void scsi_requeue_command(struct request_queue *q, struct scsi_cmnd *cmd) | 584 | static void scsi_requeue_command(struct request_queue *q, struct scsi_cmnd *cmd) |
557 | { | 585 | { |
586 | struct request *req = cmd->request; | ||
558 | unsigned long flags; | 587 | unsigned long flags; |
559 | 588 | ||
560 | cmd->request->flags &= ~REQ_DONTPREP; | 589 | scsi_unprep_request(req); |
561 | |||
562 | spin_lock_irqsave(q->queue_lock, flags); | 590 | spin_lock_irqsave(q->queue_lock, flags); |
563 | blk_requeue_request(q, cmd->request); | 591 | blk_requeue_request(q, req); |
564 | spin_unlock_irqrestore(q->queue_lock, flags); | 592 | spin_unlock_irqrestore(q->queue_lock, flags); |
565 | 593 | ||
566 | scsi_run_queue(q); | 594 | scsi_run_queue(q); |
@@ -595,13 +623,14 @@ void scsi_run_host_queues(struct Scsi_Host *shost) | |||
595 | * | 623 | * |
596 | * Lock status: Assumed that lock is not held upon entry. | 624 | * Lock status: Assumed that lock is not held upon entry. |
597 | * | 625 | * |
598 | * Returns: cmd if requeue done or required, NULL otherwise | 626 | * Returns: cmd if requeue required, NULL otherwise. |
599 | * | 627 | * |
600 | * Notes: This is called for block device requests in order to | 628 | * Notes: This is called for block device requests in order to |
601 | * mark some number of sectors as complete. | 629 | * mark some number of sectors as complete. |
602 | * | 630 | * |
603 | * We are guaranteeing that the request queue will be goosed | 631 | * We are guaranteeing that the request queue will be goosed |
604 | * at some point during this call. | 632 | * at some point during this call. |
633 | * Notes: If cmd was requeued, upon return it will be a stale pointer. | ||
605 | */ | 634 | */ |
606 | static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate, | 635 | static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate, |
607 | int bytes, int requeue) | 636 | int bytes, int requeue) |
@@ -624,14 +653,15 @@ static struct scsi_cmnd *scsi_end_request(struct scsi_cmnd *cmd, int uptodate, | |||
624 | if (!uptodate && blk_noretry_request(req)) | 653 | if (!uptodate && blk_noretry_request(req)) |
625 | end_that_request_chunk(req, 0, leftover); | 654 | end_that_request_chunk(req, 0, leftover); |
626 | else { | 655 | else { |
627 | if (requeue) | 656 | if (requeue) { |
628 | /* | 657 | /* |
629 | * Bleah. Leftovers again. Stick the | 658 | * Bleah. Leftovers again. Stick the |
630 | * leftovers in the front of the | 659 | * leftovers in the front of the |
631 | * queue, and goose the queue again. | 660 | * queue, and goose the queue again. |
632 | */ | 661 | */ |
633 | scsi_requeue_command(q, cmd); | 662 | scsi_requeue_command(q, cmd); |
634 | 663 | cmd = NULL; | |
664 | } | ||
635 | return cmd; | 665 | return cmd; |
636 | } | 666 | } |
637 | } | 667 | } |
@@ -857,15 +887,13 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
857 | * requeueing right here - we will requeue down below | 887 | * requeueing right here - we will requeue down below |
858 | * when we handle the bad sectors. | 888 | * when we handle the bad sectors. |
859 | */ | 889 | */ |
860 | cmd = scsi_end_request(cmd, 1, good_bytes, result == 0); | ||
861 | 890 | ||
862 | /* | 891 | /* |
863 | * If the command completed without error, then either finish off the | 892 | * If the command completed without error, then either |
864 | * rest of the command, or start a new one. | 893 | * finish off the rest of the command, or start a new one. |
865 | */ | 894 | */ |
866 | if (result == 0 || cmd == NULL ) { | 895 | if (scsi_end_request(cmd, 1, good_bytes, result == 0) == NULL) |
867 | return; | 896 | return; |
868 | } | ||
869 | } | 897 | } |
870 | /* | 898 | /* |
871 | * Now, if we were good little boys and girls, Santa left us a request | 899 | * Now, if we were good little boys and girls, Santa left us a request |
@@ -880,7 +908,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
880 | * and quietly refuse further access. | 908 | * and quietly refuse further access. |
881 | */ | 909 | */ |
882 | cmd->device->changed = 1; | 910 | cmd->device->changed = 1; |
883 | cmd = scsi_end_request(cmd, 0, | 911 | scsi_end_request(cmd, 0, |
884 | this_count, 1); | 912 | this_count, 1); |
885 | return; | 913 | return; |
886 | } else { | 914 | } else { |
@@ -914,7 +942,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
914 | scsi_requeue_command(q, cmd); | 942 | scsi_requeue_command(q, cmd); |
915 | result = 0; | 943 | result = 0; |
916 | } else { | 944 | } else { |
917 | cmd = scsi_end_request(cmd, 0, this_count, 1); | 945 | scsi_end_request(cmd, 0, this_count, 1); |
918 | return; | 946 | return; |
919 | } | 947 | } |
920 | break; | 948 | break; |
@@ -931,7 +959,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
931 | dev_printk(KERN_INFO, | 959 | dev_printk(KERN_INFO, |
932 | &cmd->device->sdev_gendev, | 960 | &cmd->device->sdev_gendev, |
933 | "Device not ready.\n"); | 961 | "Device not ready.\n"); |
934 | cmd = scsi_end_request(cmd, 0, this_count, 1); | 962 | scsi_end_request(cmd, 0, this_count, 1); |
935 | return; | 963 | return; |
936 | case VOLUME_OVERFLOW: | 964 | case VOLUME_OVERFLOW: |
937 | if (!(req->flags & REQ_QUIET)) { | 965 | if (!(req->flags & REQ_QUIET)) { |
@@ -941,7 +969,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
941 | __scsi_print_command(cmd->data_cmnd); | 969 | __scsi_print_command(cmd->data_cmnd); |
942 | scsi_print_sense("", cmd); | 970 | scsi_print_sense("", cmd); |
943 | } | 971 | } |
944 | cmd = scsi_end_request(cmd, 0, block_bytes, 1); | 972 | scsi_end_request(cmd, 0, block_bytes, 1); |
945 | return; | 973 | return; |
946 | default: | 974 | default: |
947 | break; | 975 | break; |
@@ -972,7 +1000,7 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes, | |||
972 | block_bytes = req->hard_cur_sectors << 9; | 1000 | block_bytes = req->hard_cur_sectors << 9; |
973 | if (!block_bytes) | 1001 | if (!block_bytes) |
974 | block_bytes = req->data_len; | 1002 | block_bytes = req->data_len; |
975 | cmd = scsi_end_request(cmd, 0, block_bytes, 1); | 1003 | scsi_end_request(cmd, 0, block_bytes, 1); |
976 | } | 1004 | } |
977 | } | 1005 | } |
978 | EXPORT_SYMBOL(scsi_io_completion); | 1006 | EXPORT_SYMBOL(scsi_io_completion); |
@@ -1118,7 +1146,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) | |||
1118 | if (unlikely(!scsi_device_online(sdev))) { | 1146 | if (unlikely(!scsi_device_online(sdev))) { |
1119 | printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to offline device\n", | 1147 | printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to offline device\n", |
1120 | sdev->host->host_no, sdev->id, sdev->lun); | 1148 | sdev->host->host_no, sdev->id, sdev->lun); |
1121 | return BLKPREP_KILL; | 1149 | goto kill; |
1122 | } | 1150 | } |
1123 | if (unlikely(sdev->sdev_state != SDEV_RUNNING)) { | 1151 | if (unlikely(sdev->sdev_state != SDEV_RUNNING)) { |
1124 | /* OK, we're not in a running state don't prep | 1152 | /* OK, we're not in a running state don't prep |
@@ -1128,7 +1156,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) | |||
1128 | * at all allowed down */ | 1156 | * at all allowed down */ |
1129 | printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to dead device\n", | 1157 | printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to dead device\n", |
1130 | sdev->host->host_no, sdev->id, sdev->lun); | 1158 | sdev->host->host_no, sdev->id, sdev->lun); |
1131 | return BLKPREP_KILL; | 1159 | goto kill; |
1132 | } | 1160 | } |
1133 | /* OK, we only allow special commands (i.e. not | 1161 | /* OK, we only allow special commands (i.e. not |
1134 | * user initiated ones */ | 1162 | * user initiated ones */ |
@@ -1160,11 +1188,11 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) | |||
1160 | if(unlikely(specials_only) && !(req->flags & REQ_SPECIAL)) { | 1188 | if(unlikely(specials_only) && !(req->flags & REQ_SPECIAL)) { |
1161 | if(specials_only == SDEV_QUIESCE || | 1189 | if(specials_only == SDEV_QUIESCE || |
1162 | specials_only == SDEV_BLOCK) | 1190 | specials_only == SDEV_BLOCK) |
1163 | return BLKPREP_DEFER; | 1191 | goto defer; |
1164 | 1192 | ||
1165 | printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to device being removed\n", | 1193 | printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to device being removed\n", |
1166 | sdev->host->host_no, sdev->id, sdev->lun); | 1194 | sdev->host->host_no, sdev->id, sdev->lun); |
1167 | return BLKPREP_KILL; | 1195 | goto kill; |
1168 | } | 1196 | } |
1169 | 1197 | ||
1170 | 1198 | ||
@@ -1182,7 +1210,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) | |||
1182 | cmd->tag = req->tag; | 1210 | cmd->tag = req->tag; |
1183 | } else { | 1211 | } else { |
1184 | blk_dump_rq_flags(req, "SCSI bad req"); | 1212 | blk_dump_rq_flags(req, "SCSI bad req"); |
1185 | return BLKPREP_KILL; | 1213 | goto kill; |
1186 | } | 1214 | } |
1187 | 1215 | ||
1188 | /* note the overloading of req->special. When the tag | 1216 | /* note the overloading of req->special. When the tag |
@@ -1220,8 +1248,13 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) | |||
1220 | * required). | 1248 | * required). |
1221 | */ | 1249 | */ |
1222 | ret = scsi_init_io(cmd); | 1250 | ret = scsi_init_io(cmd); |
1223 | if (ret) /* BLKPREP_KILL return also releases the command */ | 1251 | switch(ret) { |
1224 | return ret; | 1252 | case BLKPREP_KILL: |
1253 | /* BLKPREP_KILL return also releases the command */ | ||
1254 | goto kill; | ||
1255 | case BLKPREP_DEFER: | ||
1256 | goto defer; | ||
1257 | } | ||
1225 | 1258 | ||
1226 | /* | 1259 | /* |
1227 | * Initialize the actual SCSI command for this request. | 1260 | * Initialize the actual SCSI command for this request. |
@@ -1231,7 +1264,7 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) | |||
1231 | if (unlikely(!drv->init_command(cmd))) { | 1264 | if (unlikely(!drv->init_command(cmd))) { |
1232 | scsi_release_buffers(cmd); | 1265 | scsi_release_buffers(cmd); |
1233 | scsi_put_command(cmd); | 1266 | scsi_put_command(cmd); |
1234 | return BLKPREP_KILL; | 1267 | goto kill; |
1235 | } | 1268 | } |
1236 | } else { | 1269 | } else { |
1237 | memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd)); | 1270 | memcpy(cmd->cmnd, req->cmd, sizeof(cmd->cmnd)); |
@@ -1262,6 +1295,9 @@ static int scsi_prep_fn(struct request_queue *q, struct request *req) | |||
1262 | if (sdev->device_busy == 0) | 1295 | if (sdev->device_busy == 0) |
1263 | blk_plug_device(q); | 1296 | blk_plug_device(q); |
1264 | return BLKPREP_DEFER; | 1297 | return BLKPREP_DEFER; |
1298 | kill: | ||
1299 | req->errors = DID_NO_CONNECT << 16; | ||
1300 | return BLKPREP_KILL; | ||
1265 | } | 1301 | } |
1266 | 1302 | ||
1267 | /* | 1303 | /* |
@@ -1336,19 +1372,24 @@ static inline int scsi_host_queue_ready(struct request_queue *q, | |||
1336 | } | 1372 | } |
1337 | 1373 | ||
1338 | /* | 1374 | /* |
1339 | * Kill requests for a dead device | 1375 | * Kill a request for a dead device |
1340 | */ | 1376 | */ |
1341 | static void scsi_kill_requests(request_queue_t *q) | 1377 | static void scsi_kill_request(struct request *req, request_queue_t *q) |
1342 | { | 1378 | { |
1343 | struct request *req; | 1379 | struct scsi_cmnd *cmd = req->special; |
1380 | |||
1381 | blkdev_dequeue_request(req); | ||
1344 | 1382 | ||
1345 | while ((req = elv_next_request(q)) != NULL) { | 1383 | if (unlikely(cmd == NULL)) { |
1346 | blkdev_dequeue_request(req); | 1384 | printk(KERN_CRIT "impossible request in %s.\n", |
1347 | req->flags |= REQ_QUIET; | 1385 | __FUNCTION__); |
1348 | while (end_that_request_first(req, 0, req->nr_sectors)) | 1386 | BUG(); |
1349 | ; | ||
1350 | end_that_request_last(req); | ||
1351 | } | 1387 | } |
1388 | |||
1389 | scsi_init_cmd_errh(cmd); | ||
1390 | cmd->result = DID_NO_CONNECT << 16; | ||
1391 | atomic_inc(&cmd->device->iorequest_cnt); | ||
1392 | __scsi_done(cmd); | ||
1352 | } | 1393 | } |
1353 | 1394 | ||
1354 | /* | 1395 | /* |
@@ -1371,7 +1412,8 @@ static void scsi_request_fn(struct request_queue *q) | |||
1371 | 1412 | ||
1372 | if (!sdev) { | 1413 | if (!sdev) { |
1373 | printk("scsi: killing requests for dead queue\n"); | 1414 | printk("scsi: killing requests for dead queue\n"); |
1374 | scsi_kill_requests(q); | 1415 | while ((req = elv_next_request(q)) != NULL) |
1416 | scsi_kill_request(req, q); | ||
1375 | return; | 1417 | return; |
1376 | } | 1418 | } |
1377 | 1419 | ||
@@ -1398,11 +1440,7 @@ static void scsi_request_fn(struct request_queue *q) | |||
1398 | if (unlikely(!scsi_device_online(sdev))) { | 1440 | if (unlikely(!scsi_device_online(sdev))) { |
1399 | printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to offline device\n", | 1441 | printk(KERN_ERR "scsi%d (%d:%d): rejecting I/O to offline device\n", |
1400 | sdev->host->host_no, sdev->id, sdev->lun); | 1442 | sdev->host->host_no, sdev->id, sdev->lun); |
1401 | blkdev_dequeue_request(req); | 1443 | scsi_kill_request(req, q); |
1402 | req->flags |= REQ_QUIET; | ||
1403 | while (end_that_request_first(req, 0, req->nr_sectors)) | ||
1404 | ; | ||
1405 | end_that_request_last(req); | ||
1406 | continue; | 1444 | continue; |
1407 | } | 1445 | } |
1408 | 1446 | ||
@@ -1415,6 +1453,14 @@ static void scsi_request_fn(struct request_queue *q) | |||
1415 | sdev->device_busy++; | 1453 | sdev->device_busy++; |
1416 | 1454 | ||
1417 | spin_unlock(q->queue_lock); | 1455 | spin_unlock(q->queue_lock); |
1456 | cmd = req->special; | ||
1457 | if (unlikely(cmd == NULL)) { | ||
1458 | printk(KERN_CRIT "impossible request in %s.\n" | ||
1459 | "please mail a stack trace to " | ||
1460 | "linux-scsi@vger.kernel.org", | ||
1461 | __FUNCTION__); | ||
1462 | BUG(); | ||
1463 | } | ||
1418 | spin_lock(shost->host_lock); | 1464 | spin_lock(shost->host_lock); |
1419 | 1465 | ||
1420 | if (!scsi_host_queue_ready(q, shost, sdev)) | 1466 | if (!scsi_host_queue_ready(q, shost, sdev)) |
@@ -1433,15 +1479,6 @@ static void scsi_request_fn(struct request_queue *q) | |||
1433 | */ | 1479 | */ |
1434 | spin_unlock_irq(shost->host_lock); | 1480 | spin_unlock_irq(shost->host_lock); |
1435 | 1481 | ||
1436 | cmd = req->special; | ||
1437 | if (unlikely(cmd == NULL)) { | ||
1438 | printk(KERN_CRIT "impossible request in %s.\n" | ||
1439 | "please mail a stack trace to " | ||
1440 | "linux-scsi@vger.kernel.org", | ||
1441 | __FUNCTION__); | ||
1442 | BUG(); | ||
1443 | } | ||
1444 | |||
1445 | /* | 1482 | /* |
1446 | * Finally, initialize any error handling parameters, and set up | 1483 | * Finally, initialize any error handling parameters, and set up |
1447 | * the timers for timeouts. | 1484 | * the timers for timeouts. |
@@ -1477,6 +1514,7 @@ static void scsi_request_fn(struct request_queue *q) | |||
1477 | * cases (host limits or settings) should run the queue at some | 1514 | * cases (host limits or settings) should run the queue at some |
1478 | * later time. | 1515 | * later time. |
1479 | */ | 1516 | */ |
1517 | scsi_unprep_request(req); | ||
1480 | spin_lock_irq(q->queue_lock); | 1518 | spin_lock_irq(q->queue_lock); |
1481 | blk_requeue_request(q, req); | 1519 | blk_requeue_request(q, req); |
1482 | sdev->device_busy--; | 1520 | sdev->device_busy--; |