lib/scsi: Pass SCSI task to SCSI layer to get DIF context
By the recent refactoring, SCSI task is configured when getting DIF context from SCSI layer. Passing not CDB and offset separately but SCSI task to SCSI layer is more concise and do in this patch. In iscsi_send_datain(), we have to update task->scsi.offset for the case that data is split into a sequence, but the update is no harm because task has completed what it must to do. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I153352dfa7aa7325db4452f03d863df11b3e0cfa Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472510 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Changpeng Liu <changpeng.liu@intel.com> Reviewed-by: Paul Luse <paul.e.luse@intel.com>
This commit is contained in:
parent
f924c94b4c
commit
84e64cc9d7
@ -529,14 +529,13 @@ void spdk_scsi_lun_free_io_channel(struct spdk_scsi_lun_desc *desc);
|
||||
* Get DIF context for SCSI LUN and SCSI command.
|
||||
*
|
||||
* \param lun Logical unit.
|
||||
* \param cdb SCSI CDB.
|
||||
* \param data_offset Byte offset in the payload.
|
||||
* \param task SCSI task which has the payload.
|
||||
* \param dif_ctx Output parameter which will contain initialized DIF context.
|
||||
*
|
||||
* \return true on success or false otherwise.
|
||||
*/
|
||||
bool spdk_scsi_lun_get_dif_ctx(struct spdk_scsi_lun *lun, uint8_t *cdb,
|
||||
uint32_t data_offset, struct spdk_dif_ctx *dif_ctx);
|
||||
bool spdk_scsi_lun_get_dif_ctx(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task,
|
||||
struct spdk_dif_ctx *dif_ctx);
|
||||
|
||||
/**
|
||||
* Set iSCSI Initiator port TransportID
|
||||
|
@ -2992,6 +2992,7 @@ iscsi_send_datain(struct spdk_iscsi_conn *conn,
|
||||
offset += primary->scsi.data_transferred;
|
||||
}
|
||||
to_be32(&rsph->buffer_offset, (uint32_t)offset);
|
||||
task->scsi.offset = offset;
|
||||
|
||||
if (F_bit && S_bit) {
|
||||
to_be32(&rsph->res_cnt, residual_len);
|
||||
@ -2999,7 +3000,7 @@ iscsi_send_datain(struct spdk_iscsi_conn *conn,
|
||||
|
||||
lun_dev = spdk_scsi_dev_get_lun(conn->dev, task->lun_id);
|
||||
if (spdk_likely(lun_dev != NULL)) {
|
||||
if (spdk_unlikely(spdk_scsi_lun_get_dif_ctx(lun_dev, task->scsi.cdb, offset,
|
||||
if (spdk_unlikely(spdk_scsi_lun_get_dif_ctx(lun_dev, &task->scsi,
|
||||
&rsp_pdu->dif_ctx))) {
|
||||
rsp_pdu->dif_insert_or_strip = true;
|
||||
}
|
||||
@ -3467,7 +3468,7 @@ iscsi_pdu_hdr_op_scsi(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
||||
return iscsi_reject(conn, pdu, ISCSI_REASON_PROTOCOL_ERROR);
|
||||
}
|
||||
|
||||
if (spdk_unlikely(spdk_scsi_lun_get_dif_ctx(task->scsi.lun, cdb, 0, &pdu->dif_ctx))) {
|
||||
if (spdk_unlikely(spdk_scsi_lun_get_dif_ctx(task->scsi.lun, &task->scsi, &pdu->dif_ctx))) {
|
||||
pdu->dif_insert_or_strip = true;
|
||||
}
|
||||
} else {
|
||||
@ -4499,8 +4500,7 @@ iscsi_pdu_hdr_op_data(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (spdk_unlikely(spdk_scsi_lun_get_dif_ctx(lun_dev, subtask->scsi.cdb, buffer_offset,
|
||||
&pdu->dif_ctx))) {
|
||||
if (spdk_unlikely(spdk_scsi_lun_get_dif_ctx(lun_dev, &subtask->scsi, &pdu->dif_ctx))) {
|
||||
pdu->dif_insert_or_strip = true;
|
||||
}
|
||||
|
||||
|
@ -601,8 +601,8 @@ spdk_scsi_lun_is_removing(const struct spdk_scsi_lun *lun)
|
||||
}
|
||||
|
||||
bool
|
||||
spdk_scsi_lun_get_dif_ctx(struct spdk_scsi_lun *lun, uint8_t *cdb,
|
||||
uint32_t data_offset, struct spdk_dif_ctx *dif_ctx)
|
||||
spdk_scsi_lun_get_dif_ctx(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task,
|
||||
struct spdk_dif_ctx *dif_ctx)
|
||||
{
|
||||
return spdk_scsi_bdev_get_dif_ctx(lun->bdev, cdb, data_offset, dif_ctx);
|
||||
return spdk_scsi_bdev_get_dif_ctx(lun->bdev, task, dif_ctx);
|
||||
}
|
||||
|
@ -2008,16 +2008,20 @@ spdk_bdev_scsi_reset(struct spdk_scsi_task *task)
|
||||
}
|
||||
|
||||
bool
|
||||
spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, uint8_t *cdb,
|
||||
uint32_t data_offset, struct spdk_dif_ctx *dif_ctx)
|
||||
spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
|
||||
struct spdk_dif_ctx *dif_ctx)
|
||||
{
|
||||
uint32_t ref_tag = 0, dif_check_flags = 0;
|
||||
uint32_t ref_tag = 0, dif_check_flags = 0, data_offset;
|
||||
uint8_t *cdb;
|
||||
int rc;
|
||||
|
||||
if (spdk_likely(spdk_bdev_get_md_size(bdev) == 0)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
cdb = task->cdb;
|
||||
data_offset = task->offset;
|
||||
|
||||
/* We use lower 32 bits of LBA as Reference. Tag */
|
||||
switch (cdb[0]) {
|
||||
case SPDK_SBC_READ_6:
|
||||
|
@ -203,7 +203,7 @@ void spdk_scsi_port_destruct(struct spdk_scsi_port *port);
|
||||
int spdk_bdev_scsi_execute(struct spdk_scsi_task *task);
|
||||
void spdk_bdev_scsi_reset(struct spdk_scsi_task *task);
|
||||
|
||||
bool spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, uint8_t *cdb, uint32_t data_offset,
|
||||
bool spdk_scsi_bdev_get_dif_ctx(struct spdk_bdev *bdev, struct spdk_scsi_task *task,
|
||||
struct spdk_dif_ctx *dif_ctx);
|
||||
|
||||
int spdk_scsi_pr_out(struct spdk_scsi_task *task, uint8_t *cdb, uint8_t *data, uint16_t data_len);
|
||||
|
@ -122,7 +122,7 @@ DEFINE_STUB(spdk_scsi_lun_id_int_to_fmt, uint64_t, (int lun_id), 0);
|
||||
DEFINE_STUB(spdk_scsi_lun_id_fmt_to_int, int, (uint64_t lun_fmt), 0);
|
||||
|
||||
DEFINE_STUB(spdk_scsi_lun_get_dif_ctx, bool,
|
||||
(struct spdk_scsi_lun *lun, uint8_t *cdb, uint32_t data_offset,
|
||||
(struct spdk_scsi_lun *lun, struct spdk_scsi_task *task,
|
||||
struct spdk_dif_ctx *dif_ctx), false);
|
||||
|
||||
static void
|
||||
|
@ -965,34 +965,35 @@ static void
|
||||
get_dif_ctx_test(void)
|
||||
{
|
||||
struct spdk_bdev bdev = {};
|
||||
struct spdk_scsi_task task = {};
|
||||
struct spdk_dif_ctx dif_ctx = {};
|
||||
uint8_t cdb[16];
|
||||
uint32_t data_offset;
|
||||
bool ret;
|
||||
|
||||
cdb[0] = SPDK_SBC_READ_6;
|
||||
cdb[1] = 0x12;
|
||||
cdb[2] = 0x34;
|
||||
cdb[3] = 0x50;
|
||||
data_offset = 0x6 * 512;
|
||||
task.cdb = cdb;
|
||||
task.offset = 0x6 * 512;
|
||||
|
||||
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, cdb, data_offset, &dif_ctx);
|
||||
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, &task, &dif_ctx);
|
||||
CU_ASSERT(ret == true);
|
||||
CU_ASSERT(dif_ctx.init_ref_tag + dif_ctx.ref_tag_offset == 0x123456);
|
||||
|
||||
cdb[0] = SPDK_SBC_WRITE_12;
|
||||
to_be32(&cdb[2], 0x12345670);
|
||||
data_offset = 0x8 * 512;
|
||||
task.offset = 0x8 * 512;
|
||||
|
||||
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, cdb, data_offset, &dif_ctx);
|
||||
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, &task, &dif_ctx);
|
||||
CU_ASSERT(ret == true);
|
||||
CU_ASSERT(dif_ctx.init_ref_tag + dif_ctx.ref_tag_offset == 0x12345678);
|
||||
|
||||
cdb[0] = SPDK_SBC_WRITE_16;
|
||||
to_be64(&cdb[2], 0x0000000012345670);
|
||||
data_offset = 0x8 * 512;
|
||||
task.offset = 0x8 * 512;
|
||||
|
||||
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, cdb, data_offset, &dif_ctx);
|
||||
ret = spdk_scsi_bdev_get_dif_ctx(&bdev, &task, &dif_ctx);
|
||||
CU_ASSERT(ret == true);
|
||||
CU_ASSERT(dif_ctx.init_ref_tag + dif_ctx.ref_tag_offset == 0x12345678);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user