lib/scsi: Consolidate error paths in bdev_scsi_readwrite()
This simplifies the code a little. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: Idf53616bda21c82b82f9e9438f4dcb87ffaa59a6 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472518 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
parent
ca0972d3b8
commit
16dbc19508
@ -1292,6 +1292,7 @@ bdev_scsi_readwrite(struct spdk_bdev *bdev, struct spdk_bdev_desc *bdev_desc,
|
||||
{
|
||||
uint64_t bdev_num_blocks, offset_blocks, num_blocks;
|
||||
uint32_t max_xfer_len, block_size;
|
||||
int sk = SPDK_SCSI_SENSE_NO_SENSE, asc = SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE;
|
||||
int rc;
|
||||
|
||||
task->data_transferred = 0;
|
||||
@ -1299,21 +1300,15 @@ bdev_scsi_readwrite(struct spdk_bdev *bdev, struct spdk_bdev_desc *bdev_desc,
|
||||
if (spdk_unlikely(task->dxfer_dir != SPDK_SCSI_DIR_NONE &&
|
||||
task->dxfer_dir != (is_read ? SPDK_SCSI_DIR_FROM_DEV : SPDK_SCSI_DIR_TO_DEV))) {
|
||||
SPDK_ERRLOG("Incorrect data direction\n");
|
||||
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
||||
SPDK_SCSI_SENSE_NO_SENSE,
|
||||
SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE,
|
||||
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
||||
return SPDK_SCSI_TASK_COMPLETE;
|
||||
goto check_condition;
|
||||
}
|
||||
|
||||
bdev_num_blocks = spdk_bdev_get_num_blocks(bdev);
|
||||
if (spdk_unlikely(bdev_num_blocks <= lba || bdev_num_blocks - lba < xfer_len)) {
|
||||
SPDK_DEBUGLOG(SPDK_LOG_SCSI, "end of media\n");
|
||||
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
||||
SPDK_SCSI_SENSE_ILLEGAL_REQUEST,
|
||||
SPDK_SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE,
|
||||
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
||||
return SPDK_SCSI_TASK_COMPLETE;
|
||||
sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST;
|
||||
asc = SPDK_SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
|
||||
goto check_condition;
|
||||
}
|
||||
|
||||
if (spdk_unlikely(xfer_len == 0)) {
|
||||
@ -1328,11 +1323,9 @@ bdev_scsi_readwrite(struct spdk_bdev *bdev, struct spdk_bdev_desc *bdev_desc,
|
||||
if (spdk_unlikely(xfer_len > max_xfer_len)) {
|
||||
SPDK_ERRLOG("xfer_len %" PRIu32 " > maximum transfer length %" PRIu32 "\n",
|
||||
xfer_len, max_xfer_len);
|
||||
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
||||
SPDK_SCSI_SENSE_ILLEGAL_REQUEST,
|
||||
SPDK_SCSI_ASC_INVALID_FIELD_IN_CDB,
|
||||
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
||||
return SPDK_SCSI_TASK_COMPLETE;
|
||||
sk = SPDK_SCSI_SENSE_ILLEGAL_REQUEST;
|
||||
asc = SPDK_SCSI_ASC_INVALID_FIELD_IN_CDB;
|
||||
goto check_condition;
|
||||
}
|
||||
|
||||
if (!is_read) {
|
||||
@ -1340,22 +1333,14 @@ bdev_scsi_readwrite(struct spdk_bdev *bdev, struct spdk_bdev_desc *bdev_desc,
|
||||
if (xfer_len * block_size > task->transfer_len) {
|
||||
SPDK_ERRLOG("xfer_len %" PRIu32 " * block_size %" PRIu32 " > transfer_len %u\n",
|
||||
xfer_len, block_size, task->transfer_len);
|
||||
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
||||
SPDK_SCSI_SENSE_NO_SENSE,
|
||||
SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE,
|
||||
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
||||
return SPDK_SCSI_TASK_COMPLETE;
|
||||
goto check_condition;
|
||||
}
|
||||
}
|
||||
|
||||
if (_bytes_to_blocks(block_size, task->offset, &offset_blocks, task->length, &num_blocks) != 0) {
|
||||
SPDK_ERRLOG("task's offset %" PRIu64 " or length %" PRIu32 " is not block multiple\n",
|
||||
task->offset, task->length);
|
||||
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
||||
SPDK_SCSI_SENSE_NO_SENSE,
|
||||
SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE,
|
||||
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
||||
return SPDK_SCSI_TASK_COMPLETE;
|
||||
goto check_condition;
|
||||
}
|
||||
|
||||
offset_blocks += lba;
|
||||
@ -1380,15 +1365,16 @@ bdev_scsi_readwrite(struct spdk_bdev *bdev, struct spdk_bdev_desc *bdev_desc,
|
||||
return SPDK_SCSI_TASK_PENDING;
|
||||
}
|
||||
SPDK_ERRLOG("spdk_bdev_%s_blocks() failed\n", is_read ? "readv" : "writev");
|
||||
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
|
||||
SPDK_SCSI_SENSE_NO_SENSE,
|
||||
SPDK_SCSI_ASC_NO_ADDITIONAL_SENSE,
|
||||
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
||||
return SPDK_SCSI_TASK_COMPLETE;
|
||||
goto check_condition;
|
||||
}
|
||||
|
||||
task->data_transferred = task->length;
|
||||
return SPDK_SCSI_TASK_PENDING;
|
||||
|
||||
check_condition:
|
||||
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION, sk, asc,
|
||||
SPDK_SCSI_ASCQ_CAUSE_NOT_REPORTABLE);
|
||||
return SPDK_SCSI_TASK_COMPLETE;
|
||||
}
|
||||
|
||||
struct spdk_bdev_scsi_unmap_ctx {
|
||||
|
Loading…
Reference in New Issue
Block a user