Commit c092d4ec authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

scsi: simplify scsi_prep_state_check

Return a blk_status_t directly, and make the code a little more compact
by handling the fast path in the caller.
Reviewed-by: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 535ac5d3
...@@ -1240,16 +1240,9 @@ static int scsi_setup_cmnd(struct scsi_device *sdev, struct request *req) ...@@ -1240,16 +1240,9 @@ static int scsi_setup_cmnd(struct scsi_device *sdev, struct request *req)
return scsi_setup_fs_cmnd(sdev, req); return scsi_setup_fs_cmnd(sdev, req);
} }
static int static blk_status_t
scsi_prep_state_check(struct scsi_device *sdev, struct request *req) scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
{ {
int ret = BLKPREP_OK;
/*
* If the device is not in running state we will reject some
* or all commands.
*/
if (unlikely(sdev->sdev_state != SDEV_RUNNING)) {
switch (sdev->sdev_state) { switch (sdev->sdev_state) {
case SDEV_OFFLINE: case SDEV_OFFLINE:
case SDEV_TRANSPORT_OFFLINE: case SDEV_TRANSPORT_OFFLINE:
...@@ -1260,8 +1253,7 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req) ...@@ -1260,8 +1253,7 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
*/ */
sdev_printk(KERN_ERR, sdev, sdev_printk(KERN_ERR, sdev,
"rejecting I/O to offline device\n"); "rejecting I/O to offline device\n");
ret = BLKPREP_KILL; return BLK_STS_IOERR;
break;
case SDEV_DEL: case SDEV_DEL:
/* /*
* If the device is fully deleted, we refuse to * If the device is fully deleted, we refuse to
...@@ -1269,19 +1261,17 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req) ...@@ -1269,19 +1261,17 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
*/ */
sdev_printk(KERN_ERR, sdev, sdev_printk(KERN_ERR, sdev,
"rejecting I/O to dead device\n"); "rejecting I/O to dead device\n");
ret = BLKPREP_KILL; return BLK_STS_IOERR;
break;
case SDEV_BLOCK: case SDEV_BLOCK:
case SDEV_CREATED_BLOCK: case SDEV_CREATED_BLOCK:
ret = BLKPREP_DEFER; return BLK_STS_RESOURCE;
break;
case SDEV_QUIESCE: case SDEV_QUIESCE:
/* /*
* If the devices is blocked we defer normal commands. * If the devices is blocked we defer normal commands.
*/ */
if (req && !(req->rq_flags & RQF_PREEMPT)) if (req && !(req->rq_flags & RQF_PREEMPT))
ret = BLKPREP_DEFER; return BLK_STS_RESOURCE;
break; return BLK_STS_OK;
default: default:
/* /*
* For any other not fully online state we only allow * For any other not fully online state we only allow
...@@ -1289,11 +1279,9 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req) ...@@ -1289,11 +1279,9 @@ scsi_prep_state_check(struct scsi_device *sdev, struct request *req)
* command is not allowed. * command is not allowed.
*/ */
if (req && !(req->rq_flags & RQF_PREEMPT)) if (req && !(req->rq_flags & RQF_PREEMPT))
ret = BLKPREP_KILL; return BLK_STS_IOERR;
break; return BLK_STS_OK;
}
} }
return ret;
} }
/* /*
...@@ -1700,9 +1688,15 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx, ...@@ -1700,9 +1688,15 @@ static blk_status_t scsi_queue_rq(struct blk_mq_hw_ctx *hctx,
blk_status_t ret; blk_status_t ret;
int reason; int reason;
ret = prep_to_mq(scsi_prep_state_check(sdev, req)); /*
* If the device is not in running state we will reject some or all
* commands.
*/
if (unlikely(sdev->sdev_state != SDEV_RUNNING)) {
ret = scsi_prep_state_check(sdev, req);
if (ret != BLK_STS_OK) if (ret != BLK_STS_OK)
goto out_put_budget; goto out_put_budget;
}
ret = BLK_STS_RESOURCE; ret = BLK_STS_RESOURCE;
if (!scsi_target_queue_ready(shost, sdev)) if (!scsi_target_queue_ready(shost, sdev))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment