Skip to content

Commit f6d47e7

Browse files
author
Christoph Hellwig
committed
scsi: unwind blk_end_request_all and blk_end_request_err calls
Replace the calls to the various blk_end_request variants with opencode equivalents. Blk-mq is using a model that gives the driver control between the bio updates and the actual completion, and making the old code follow that same model allows us to keep the code more similar for both paths. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Webb Scales <[email protected]> Acked-by: Jens Axboe <[email protected]> Tested-by: Bart Van Assche <[email protected]> Tested-by: Robert Elliott <[email protected]>
1 parent 2ccbb00 commit f6d47e7

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

drivers/scsi/scsi_lib.c

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,37 @@ static void scsi_release_bidi_buffers(struct scsi_cmnd *cmd)
621621
cmd->request->next_rq->special = NULL;
622622
}
623623

624+
static bool scsi_end_request(struct request *req, int error,
625+
unsigned int bytes, unsigned int bidi_bytes)
626+
{
627+
struct scsi_cmnd *cmd = req->special;
628+
struct scsi_device *sdev = cmd->device;
629+
struct request_queue *q = sdev->request_queue;
630+
unsigned long flags;
631+
632+
633+
if (blk_update_request(req, error, bytes))
634+
return true;
635+
636+
/* Bidi request must be completed as a whole */
637+
if (unlikely(bidi_bytes) &&
638+
blk_update_request(req->next_rq, error, bidi_bytes))
639+
return true;
640+
641+
if (blk_queue_add_random(q))
642+
add_disk_randomness(req->rq_disk);
643+
644+
spin_lock_irqsave(q->queue_lock, flags);
645+
blk_finish_request(req, error);
646+
spin_unlock_irqrestore(q->queue_lock, flags);
647+
648+
if (bidi_bytes)
649+
scsi_release_bidi_buffers(cmd);
650+
scsi_release_buffers(cmd);
651+
scsi_next_command(cmd);
652+
return false;
653+
}
654+
624655
/**
625656
* __scsi_error_from_host_byte - translate SCSI error code into errno
626657
* @cmd: SCSI command (unused)
@@ -693,7 +724,7 @@ static int __scsi_error_from_host_byte(struct scsi_cmnd *cmd, int result)
693724
* be put back on the queue and retried using the same
694725
* command as before, possibly after a delay.
695726
*
696-
* c) We can call blk_end_request() with -EIO to fail
727+
* c) We can call scsi_end_request() with -EIO to fail
697728
* the remainder of the request.
698729
*/
699730
void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
@@ -744,13 +775,9 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
744775
* both sides at once.
745776
*/
746777
req->next_rq->resid_len = scsi_in(cmd)->resid;
747-
748-
scsi_release_buffers(cmd);
749-
scsi_release_bidi_buffers(cmd);
750-
751-
blk_end_request_all(req, 0);
752-
753-
scsi_next_command(cmd);
778+
if (scsi_end_request(req, 0, blk_rq_bytes(req),
779+
blk_rq_bytes(req->next_rq)))
780+
BUG();
754781
return;
755782
}
756783
} else if (blk_rq_bytes(req) == 0 && result && !sense_deferred) {
@@ -797,15 +824,16 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
797824
/*
798825
* If we finished all bytes in the request we are done now.
799826
*/
800-
if (!blk_end_request(req, error, good_bytes))
801-
goto next_command;
827+
if (!scsi_end_request(req, error, good_bytes, 0))
828+
return;
802829

803830
/*
804831
* Kill remainder if no retrys.
805832
*/
806833
if (error && scsi_noretry_cmd(cmd)) {
807-
blk_end_request_all(req, error);
808-
goto next_command;
834+
if (scsi_end_request(req, error, blk_rq_bytes(req), 0))
835+
BUG();
836+
return;
809837
}
810838

811839
/*
@@ -919,8 +947,8 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
919947
scsi_print_sense("", cmd);
920948
scsi_print_command(cmd);
921949
}
922-
if (!blk_end_request_err(req, error))
923-
goto next_command;
950+
if (!scsi_end_request(req, error, blk_rq_err_bytes(req), 0))
951+
return;
924952
/*FALLTHRU*/
925953
case ACTION_REPREP:
926954
requeue:
@@ -939,11 +967,6 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
939967
__scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY, 0);
940968
break;
941969
}
942-
return;
943-
944-
next_command:
945-
scsi_release_buffers(cmd);
946-
scsi_next_command(cmd);
947970
}
948971

949972
static int scsi_init_sgtable(struct request *req, struct scsi_data_buffer *sdb,

0 commit comments

Comments
 (0)