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,60 +1240,48 @@ static int scsi_setup_cmnd(struct scsi_device *sdev, struct request *req) ...@@ -1240,60 +1240,48 @@ 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; switch (sdev->sdev_state) {
case SDEV_OFFLINE:
/* case SDEV_TRANSPORT_OFFLINE:
* If the device is not in running state we will reject some /*
* or all commands. * If the device is offline we refuse to process any
*/ * commands. The device must be brought online
if (unlikely(sdev->sdev_state != SDEV_RUNNING)) { * before trying any recovery commands.
switch (sdev->sdev_state) { */
case SDEV_OFFLINE: sdev_printk(KERN_ERR, sdev,
case SDEV_TRANSPORT_OFFLINE: "rejecting I/O to offline device\n");
/* return BLK_STS_IOERR;
* If the device is offline we refuse to process any case SDEV_DEL:
* commands. The device must be brought online /*
* before trying any recovery commands. * If the device is fully deleted, we refuse to
*/ * process any commands as well.
sdev_printk(KERN_ERR, sdev, */
"rejecting I/O to offline device\n"); sdev_printk(KERN_ERR, sdev,
ret = BLKPREP_KILL; "rejecting I/O to dead device\n");
break; return BLK_STS_IOERR;
case SDEV_DEL: case SDEV_BLOCK:
/* case SDEV_CREATED_BLOCK:
* If the device is fully deleted, we refuse to return BLK_STS_RESOURCE;
* process any commands as well. case SDEV_QUIESCE:
*/ /*
sdev_printk(KERN_ERR, sdev, * If the devices is blocked we defer normal commands.
"rejecting I/O to dead device\n"); */
ret = BLKPREP_KILL; if (req && !(req->rq_flags & RQF_PREEMPT))
break; return BLK_STS_RESOURCE;
case SDEV_BLOCK: return BLK_STS_OK;
case SDEV_CREATED_BLOCK: default:
ret = BLKPREP_DEFER; /*
break; * For any other not fully online state we only allow
case SDEV_QUIESCE: * special commands. In particular any user initiated
/* * command is not allowed.
* If the devices is blocked we defer normal commands. */
*/ if (req && !(req->rq_flags & RQF_PREEMPT))
if (req && !(req->rq_flags & RQF_PREEMPT)) return BLK_STS_IOERR;
ret = BLKPREP_DEFER; return BLK_STS_OK;
break;
default:
/*
* For any other not fully online state we only allow
* special commands. In particular any user initiated
* command is not allowed.
*/
if (req && !(req->rq_flags & RQF_PREEMPT))
ret = BLKPREP_KILL;
break;
}
} }
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 (ret != BLK_STS_OK) * If the device is not in running state we will reject some or all
goto out_put_budget; * commands.
*/
if (unlikely(sdev->sdev_state != SDEV_RUNNING)) {
ret = scsi_prep_state_check(sdev, req);
if (ret != BLK_STS_OK)
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