scsi: pass only task to SCSI exec functions

Retrieve LUN data directly from struct spdk_scsi_lun rather than copying
them into struct spdk_scsi_task, and access the LUN via the task->lun
pointer.

Change-Id: Id8745f116bc559fb2f9e58811c2b9781c8cbdae8
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/393709
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: <shuhei.matsumoto.xt@hitachi.com>
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
Daniel Verkamp 2018-01-04 15:45:01 -07:00
parent ec25ddd9cf
commit d57306d8eb
6 changed files with 77 additions and 60 deletions

View File

@ -100,8 +100,6 @@ struct spdk_scsi_task {
uint8_t response; /* task mgmt response */
struct spdk_scsi_lun *lun;
struct spdk_bdev_desc *desc;
struct spdk_io_channel *ch;
struct spdk_scsi_port *target_port;
struct spdk_scsi_port *initiator_port;

View File

@ -110,9 +110,6 @@ spdk_scsi_lun_task_mgmt_execute(struct spdk_scsi_task *task,
return -1;
}
task->ch = task->lun->io_channel;
task->desc = task->lun->bdev_desc;
switch (func) {
case SPDK_SCSI_TASK_FUNC_ABORT_TASK:
task->response = SPDK_SCSI_TASK_MGMT_RESP_REJECT_FUNC_NOT_SUPPORTED;
@ -125,7 +122,7 @@ spdk_scsi_lun_task_mgmt_execute(struct spdk_scsi_task *task,
break;
case SPDK_SCSI_TASK_FUNC_LUN_RESET:
spdk_bdev_scsi_reset(task->lun->bdev, task);
spdk_bdev_scsi_reset(task);
return 0;
default:
@ -196,13 +193,11 @@ spdk_scsi_lun_execute_tasks(struct spdk_scsi_lun *lun)
TAILQ_FOREACH_SAFE(task, &lun->pending_tasks, scsi_link, task_tmp) {
task->status = SPDK_SCSI_STATUS_GOOD;
task->ch = lun->io_channel;
task->desc = lun->bdev_desc;
spdk_trace_record(TRACE_SCSI_TASK_START, lun->dev->id, task->length, (uintptr_t)task, 0);
TAILQ_REMOVE(&lun->pending_tasks, task, scsi_link);
TAILQ_INSERT_TAIL(&lun->tasks, task, scsi_link);
if (!lun->removed) {
rc = spdk_bdev_scsi_execute(lun->bdev, task);
rc = spdk_bdev_scsi_execute(task);
} else {
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
SPDK_SCSI_SENSE_ABORTED_COMMAND,

View File

@ -1295,9 +1295,9 @@ spdk_bdev_scsi_task_complete_mgmt(struct spdk_bdev_io *bdev_io, bool success,
}
static int
spdk_bdev_scsi_read(struct spdk_bdev *bdev,
struct spdk_scsi_task *task, uint64_t lba,
uint32_t len)
spdk_bdev_scsi_read(struct spdk_bdev *bdev, struct spdk_bdev_desc *bdev_desc,
struct spdk_io_channel *bdev_ch, struct spdk_scsi_task *task,
uint64_t lba, uint32_t len)
{
uint64_t blen;
uint64_t offset;
@ -1314,7 +1314,7 @@ spdk_bdev_scsi_read(struct spdk_bdev *bdev,
"Read: lba=%"PRIu64", len=%"PRIu64"\n",
lba, (uint64_t)task->length / blen);
rc = spdk_bdev_readv(task->desc, task->ch, task->iovs,
rc = spdk_bdev_readv(bdev_desc, bdev_ch, task->iovs,
task->iovcnt, offset, nbytes,
spdk_bdev_scsi_task_complete_cmd, task);
if (rc) {
@ -1333,8 +1333,9 @@ spdk_bdev_scsi_read(struct spdk_bdev *bdev,
}
static int
spdk_bdev_scsi_write(struct spdk_bdev *bdev,
struct spdk_scsi_task *task, uint64_t lba, uint32_t len)
spdk_bdev_scsi_write(struct spdk_bdev *bdev, struct spdk_bdev_desc *bdev_desc,
struct spdk_io_channel *bdev_ch, struct spdk_scsi_task *task,
uint64_t lba, uint32_t len)
{
uint64_t blen;
uint64_t offset;
@ -1360,7 +1361,7 @@ spdk_bdev_scsi_write(struct spdk_bdev *bdev,
}
offset += task->offset;
rc = spdk_bdev_writev(task->desc, task->ch, task->iovs,
rc = spdk_bdev_writev(bdev_desc, bdev_ch, task->iovs,
task->iovcnt, offset, task->length,
spdk_bdev_scsi_task_complete_cmd,
task);
@ -1383,7 +1384,8 @@ spdk_bdev_scsi_write(struct spdk_bdev *bdev,
}
static int
spdk_bdev_scsi_sync(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
spdk_bdev_scsi_sync(struct spdk_bdev *bdev, struct spdk_bdev_desc *bdev_desc,
struct spdk_io_channel *bdev_ch, struct spdk_scsi_task *task,
uint64_t lba, uint32_t num_blocks)
{
uint64_t bdev_num_blocks;
@ -1405,7 +1407,7 @@ spdk_bdev_scsi_sync(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
return SPDK_SCSI_TASK_COMPLETE;
}
rc = spdk_bdev_flush_blocks(task->desc, task->ch, lba, num_blocks,
rc = spdk_bdev_flush_blocks(bdev_desc, bdev_ch, lba, num_blocks,
spdk_bdev_scsi_task_complete_cmd, task);
if (rc) {
@ -1422,10 +1424,13 @@ spdk_bdev_scsi_sync(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
}
static int
spdk_bdev_scsi_readwrite(struct spdk_bdev *bdev,
struct spdk_scsi_task *task,
spdk_bdev_scsi_readwrite(struct spdk_scsi_task *task,
uint64_t lba, uint32_t xfer_len, bool is_read)
{
struct spdk_scsi_lun *lun = task->lun;
struct spdk_bdev *bdev = lun->bdev;
struct spdk_bdev_desc *bdev_desc = lun->bdev_desc;
struct spdk_io_channel *bdev_ch = lun->io_channel;
uint64_t bdev_num_blocks;
uint32_t max_xfer_len;
@ -1469,9 +1474,9 @@ spdk_bdev_scsi_readwrite(struct spdk_bdev *bdev,
}
if (is_read) {
return spdk_bdev_scsi_read(bdev, task, lba, xfer_len);
return spdk_bdev_scsi_read(bdev, bdev_desc, bdev_ch, task, lba, xfer_len);
} else {
return spdk_bdev_scsi_write(bdev, task, lba, xfer_len);
return spdk_bdev_scsi_write(bdev, bdev_desc, bdev_ch, task, lba, xfer_len);
}
}
@ -1539,8 +1544,8 @@ __copy_desc(struct spdk_bdev_scsi_unmap_ctx *ctx, uint8_t *data, size_t data_len
}
static int
spdk_bdev_scsi_unmap(struct spdk_bdev *bdev,
struct spdk_scsi_task *task)
spdk_bdev_scsi_unmap(struct spdk_bdev *bdev, struct spdk_bdev_desc *bdev_desc,
struct spdk_io_channel *bdev_ch, struct spdk_scsi_task *task)
{
uint8_t *data;
struct spdk_bdev_scsi_unmap_ctx *ctx;
@ -1602,7 +1607,7 @@ spdk_bdev_scsi_unmap(struct spdk_bdev *bdev,
}
ctx->count++;
rc = spdk_bdev_unmap_blocks(task->desc, task->ch, offset_blocks, num_blocks,
rc = spdk_bdev_unmap_blocks(bdev_desc, bdev_ch, offset_blocks, num_blocks,
spdk_bdev_scsi_task_complete_unmap_cmd, ctx);
if (rc) {
@ -1627,9 +1632,10 @@ spdk_bdev_scsi_unmap(struct spdk_bdev *bdev,
}
static int
spdk_bdev_scsi_process_block(struct spdk_bdev *bdev,
struct spdk_scsi_task *task)
spdk_bdev_scsi_process_block(struct spdk_scsi_task *task)
{
struct spdk_scsi_lun *lun = task->lun;
struct spdk_bdev *bdev = lun->bdev;
uint64_t lba;
uint32_t xfer_len;
uint32_t len = 0;
@ -1646,27 +1652,27 @@ spdk_bdev_scsi_process_block(struct spdk_bdev *bdev,
if (xfer_len == 0) {
xfer_len = 256;
}
return spdk_bdev_scsi_readwrite(bdev, task, lba, xfer_len,
return spdk_bdev_scsi_readwrite(task, lba, xfer_len,
cdb[0] == SPDK_SBC_READ_6);
case SPDK_SBC_READ_10:
case SPDK_SBC_WRITE_10:
lba = from_be32(&cdb[2]);
xfer_len = from_be16(&cdb[7]);
return spdk_bdev_scsi_readwrite(bdev, task, lba, xfer_len,
return spdk_bdev_scsi_readwrite(task, lba, xfer_len,
cdb[0] == SPDK_SBC_READ_10);
case SPDK_SBC_READ_12:
case SPDK_SBC_WRITE_12:
lba = from_be32(&cdb[2]);
xfer_len = from_be32(&cdb[6]);
return spdk_bdev_scsi_readwrite(bdev, task, lba, xfer_len,
return spdk_bdev_scsi_readwrite(task, lba, xfer_len,
cdb[0] == SPDK_SBC_READ_12);
case SPDK_SBC_READ_16:
case SPDK_SBC_WRITE_16:
lba = from_be64(&cdb[2]);
xfer_len = from_be32(&cdb[10]);
return spdk_bdev_scsi_readwrite(bdev, task, lba, xfer_len,
return spdk_bdev_scsi_readwrite(task, lba, xfer_len,
cdb[0] == SPDK_SBC_READ_16);
case SPDK_SBC_READ_CAPACITY_10: {
@ -1735,11 +1741,11 @@ spdk_bdev_scsi_process_block(struct spdk_bdev *bdev,
len = spdk_bdev_get_num_blocks(bdev) - lba;
}
return spdk_bdev_scsi_sync(bdev, task, lba, len);
return spdk_bdev_scsi_sync(bdev, lun->bdev_desc, lun->io_channel, task, lba, len);
break;
case SPDK_SBC_UNMAP:
return spdk_bdev_scsi_unmap(bdev, task);
return spdk_bdev_scsi_unmap(bdev, lun->bdev_desc, lun->io_channel, task);
default:
return SPDK_SCSI_TASK_UNKNOWN;
@ -1764,9 +1770,10 @@ spdk_bdev_scsi_check_len(struct spdk_scsi_task *task, int len, int min_len)
}
static int
spdk_bdev_scsi_process_primary(struct spdk_bdev *bdev,
struct spdk_scsi_task *task)
spdk_bdev_scsi_process_primary(struct spdk_scsi_task *task)
{
struct spdk_scsi_lun *lun = task->lun;
struct spdk_bdev *bdev = lun->bdev;
int alloc_len = -1;
int data_len = -1;
uint8_t *cdb = task->cdb;
@ -2015,12 +2022,12 @@ spdk_bdev_scsi_process_primary(struct spdk_bdev *bdev,
}
int
spdk_bdev_scsi_execute(struct spdk_bdev *bdev, struct spdk_scsi_task *task)
spdk_bdev_scsi_execute(struct spdk_scsi_task *task)
{
int rc;
if ((rc = spdk_bdev_scsi_process_block(bdev, task)) == SPDK_SCSI_TASK_UNKNOWN) {
if ((rc = spdk_bdev_scsi_process_primary(bdev, task)) == SPDK_SCSI_TASK_UNKNOWN) {
if ((rc = spdk_bdev_scsi_process_block(task)) == SPDK_SCSI_TASK_UNKNOWN) {
if ((rc = spdk_bdev_scsi_process_primary(task)) == SPDK_SCSI_TASK_UNKNOWN) {
SPDK_DEBUGLOG(SPDK_LOG_SCSI, "unsupported SCSI OP=0x%x\n", task->cdb[0]);
/* INVALID COMMAND OPERATION CODE */
spdk_scsi_task_set_status(task, SPDK_SCSI_STATUS_CHECK_CONDITION,
@ -2035,8 +2042,10 @@ spdk_bdev_scsi_execute(struct spdk_bdev *bdev, struct spdk_scsi_task *task)
}
int
spdk_bdev_scsi_reset(struct spdk_bdev *bdev, struct spdk_scsi_task *task)
spdk_bdev_scsi_reset(struct spdk_scsi_task *task)
{
return spdk_bdev_reset(task->desc, task->ch,
struct spdk_scsi_lun *lun = task->lun;
return spdk_bdev_reset(lun->bdev_desc, lun->io_channel,
spdk_bdev_scsi_task_complete_mgmt, task);
}

View File

@ -152,8 +152,8 @@ int spdk_scsi_port_construct(struct spdk_scsi_port *port, uint64_t id,
uint16_t index, const char *name);
void spdk_scsi_port_destruct(struct spdk_scsi_port *port);
int spdk_bdev_scsi_execute(struct spdk_bdev *bdev, struct spdk_scsi_task *task);
int spdk_bdev_scsi_reset(struct spdk_bdev *bdev, struct spdk_scsi_task *task);
int spdk_bdev_scsi_execute(struct spdk_scsi_task *task);
int spdk_bdev_scsi_reset(struct spdk_scsi_task *task);
struct spdk_scsi_globals {
pthread_mutex_t mutex;

View File

@ -164,13 +164,13 @@ void spdk_scsi_dev_delete_lun(struct spdk_scsi_dev *dev,
}
int
spdk_bdev_scsi_reset(struct spdk_bdev *bdev, struct spdk_scsi_task *task)
spdk_bdev_scsi_reset(struct spdk_scsi_task *task)
{
return 0;
}
int
spdk_bdev_scsi_execute(struct spdk_bdev *bdev, struct spdk_scsi_task *task)
spdk_bdev_scsi_execute(struct spdk_scsi_task *task)
{
if (g_lun_execute_fail) {
return -EINVAL;

View File

@ -254,6 +254,7 @@ mode_select_6_test(void)
task.cdb = cdb;
snprintf(&dev.name[0], sizeof(dev.name), "spdk_iscsi_translation_test");
lun.bdev = &bdev;
lun.dev = &dev;
task.lun = &lun;
@ -262,7 +263,7 @@ mode_select_6_test(void)
data[5] = 0x02;
spdk_scsi_task_set_data(&task, data, sizeof(data));
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT_EQUAL(rc, 0);
@ -294,10 +295,11 @@ mode_select_6_test2(void)
task.cdb = cdb;
snprintf(&dev.name[0], sizeof(dev.name), "spdk_iscsi_translation_test");
lun.bdev = &bdev;
lun.dev = &dev;
task.lun = &lun;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT_EQUAL(rc, 0);
@ -333,10 +335,11 @@ mode_sense_6_test(void)
task.cdb = cdb;
snprintf(&dev.name[0], sizeof(dev.name), "spdk_iscsi_translation_test");
lun.bdev = &bdev;
lun.dev = &dev;
task.lun = &lun;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
SPDK_CU_ASSERT_FATAL(rc == 0);
data = task.iovs[0].iov_base;
@ -381,10 +384,11 @@ mode_sense_10_test(void)
task.cdb = cdb;
snprintf(&dev.name[0], sizeof(dev.name), "spdk_iscsi_translation_test");
lun.bdev = &bdev;
lun.dev = &dev;
task.lun = &lun;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
SPDK_CU_ASSERT_FATAL(rc == 0);
data = task.iovs[0].iov_base;
@ -427,10 +431,11 @@ inquiry_evpd_test(void)
task.cdb = cdb;
snprintf(&dev.name[0], sizeof(dev.name), "spdk_iscsi_translation_test");
lun.bdev = &bdev;
lun.dev = &dev;
task.lun = &lun;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
SPDK_CU_ASSERT_FATAL(rc == 0);
CU_ASSERT_EQUAL(task.status, SPDK_SCSI_STATUS_CHECK_CONDITION);
@ -468,10 +473,11 @@ inquiry_standard_test(void)
task.cdb = cdb;
snprintf(&dev.name[0], sizeof(dev.name), "spdk_iscsi_translation_test");
lun.bdev = &bdev;
lun.dev = &dev;
task.lun = &lun;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
data = task.iovs[0].iov_base;
inq_data = (struct spdk_scsi_cdb_inquiry_data *)&data[0];
@ -505,6 +511,7 @@ _inquiry_overflow_test(uint8_t alloc_len)
task.cdb = cdb;
snprintf(&dev.name[0], sizeof(dev.name), "spdk_iscsi_translation_test");
lun.bdev = &bdev;
lun.dev = &dev;
task.lun = &lun;
@ -513,7 +520,7 @@ _inquiry_overflow_test(uint8_t alloc_len)
spdk_scsi_task_set_data(&task, data, sizeof(data));
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
SPDK_CU_ASSERT_FATAL(rc == 0);
CU_ASSERT_EQUAL(memcmp(data + alloc_len, data_compare + alloc_len, sizeof(data) - alloc_len), 0);
@ -623,11 +630,15 @@ static void
lba_range_test(void)
{
struct spdk_bdev bdev;
struct spdk_scsi_lun lun;
struct spdk_scsi_task task;
uint8_t cdb[16];
int rc;
lun.bdev = &bdev;
spdk_init_task(&task);
task.lun = &lun;
task.cdb = cdb;
memset(cdb, 0, sizeof(cdb));
@ -640,7 +651,7 @@ lba_range_test(void)
to_be64(&cdb[2], 0); /* LBA */
to_be32(&cdb[10], 1); /* transfer length */
task.transfer_len = 1 * 512;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT(rc == SPDK_SCSI_TASK_PENDING);
CU_ASSERT(task.status == SPDK_SCSI_STATUS_GOOD);
@ -648,7 +659,7 @@ lba_range_test(void)
to_be64(&cdb[2], 4); /* LBA */
to_be32(&cdb[10], 1); /* transfer length */
task.transfer_len = 1 * 512;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT(rc == SPDK_SCSI_TASK_COMPLETE);
CU_ASSERT(task.status == SPDK_SCSI_STATUS_CHECK_CONDITION);
CU_ASSERT(task.sense_data[12] == SPDK_SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE);
@ -657,7 +668,7 @@ lba_range_test(void)
to_be64(&cdb[2], 0); /* LBA */
to_be32(&cdb[10], 4); /* transfer length */
task.transfer_len = 4 * 512;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT(rc == SPDK_SCSI_TASK_PENDING);
CU_ASSERT(task.status == SPDK_SCSI_STATUS_GOOD);
@ -665,7 +676,7 @@ lba_range_test(void)
to_be64(&cdb[2], 0); /* LBA */
to_be32(&cdb[10], 5); /* transfer length */
task.transfer_len = 5 * 512;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT(rc == SPDK_SCSI_TASK_COMPLETE);
CU_ASSERT(task.status == SPDK_SCSI_STATUS_CHECK_CONDITION);
CU_ASSERT(task.sense_data[12] == SPDK_SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE);
@ -677,11 +688,15 @@ static void
xfer_len_test(void)
{
struct spdk_bdev bdev;
struct spdk_scsi_lun lun;
struct spdk_scsi_task task;
uint8_t cdb[16];
int rc;
lun.bdev = &bdev;
spdk_init_task(&task);
task.lun = &lun;
task.cdb = cdb;
memset(cdb, 0, sizeof(cdb));
@ -694,7 +709,7 @@ xfer_len_test(void)
to_be64(&cdb[2], 0); /* LBA */
to_be32(&cdb[10], 1); /* transfer length */
task.transfer_len = 1 * 512;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT(rc == SPDK_SCSI_TASK_PENDING);
CU_ASSERT(task.status == SPDK_SCSI_STATUS_GOOD);
@ -702,7 +717,7 @@ xfer_len_test(void)
to_be64(&cdb[2], 0); /* LBA */
to_be32(&cdb[10], SPDK_WORK_BLOCK_SIZE / 512); /* transfer length */
task.transfer_len = SPDK_WORK_BLOCK_SIZE;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT(rc == SPDK_SCSI_TASK_PENDING);
CU_ASSERT(task.status == SPDK_SCSI_STATUS_GOOD);
@ -710,7 +725,7 @@ xfer_len_test(void)
to_be64(&cdb[2], 0); /* LBA */
to_be32(&cdb[10], SPDK_WORK_BLOCK_SIZE / 512 + 1); /* transfer length */
task.transfer_len = SPDK_WORK_BLOCK_SIZE + 512;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT(rc == SPDK_SCSI_TASK_COMPLETE);
CU_ASSERT(task.status == SPDK_SCSI_STATUS_CHECK_CONDITION);
CU_ASSERT((task.sense_data[2] & 0xf) == SPDK_SCSI_SENSE_ILLEGAL_REQUEST);
@ -720,7 +735,7 @@ xfer_len_test(void)
to_be64(&cdb[2], 0); /* LBA */
to_be32(&cdb[10], 0); /* transfer length */
task.transfer_len = 0;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT(rc == SPDK_SCSI_TASK_COMPLETE);
CU_ASSERT(task.status == SPDK_SCSI_STATUS_GOOD);
CU_ASSERT(task.data_transferred == 0);
@ -729,7 +744,7 @@ xfer_len_test(void)
to_be64(&cdb[2], g_test_bdev_num_blocks); /* LBA */
to_be32(&cdb[10], 0); /* transfer length */
task.transfer_len = 0;
rc = spdk_bdev_scsi_execute(&bdev, &task);
rc = spdk_bdev_scsi_execute(&task);
CU_ASSERT(rc == SPDK_SCSI_TASK_COMPLETE);
CU_ASSERT(task.status == SPDK_SCSI_STATUS_CHECK_CONDITION);
CU_ASSERT(task.sense_data[12] == SPDK_SCSI_ASC_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE);