diff --git a/include/spdk/scsi.h b/include/spdk/scsi.h index 1b23a083e..1b3f75577 100644 --- a/include/spdk/scsi.h +++ b/include/spdk/scsi.h @@ -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 diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 09b1f580e..ef41c1f02 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -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; } diff --git a/lib/scsi/lun.c b/lib/scsi/lun.c index 9282c4c43..e6d06952b 100644 --- a/lib/scsi/lun.c +++ b/lib/scsi/lun.c @@ -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); } diff --git a/lib/scsi/scsi_bdev.c b/lib/scsi/scsi_bdev.c index 7ff98f52e..fe26c0b74 100644 --- a/lib/scsi/scsi_bdev.c +++ b/lib/scsi/scsi_bdev.c @@ -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: diff --git a/lib/scsi/scsi_internal.h b/lib/scsi/scsi_internal.h index 3fe0f1af8..cbab5df02 100644 --- a/lib/scsi/scsi_internal.h +++ b/lib/scsi/scsi_internal.h @@ -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); diff --git a/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c b/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c index 0282aeca8..51ae4f3b5 100644 --- a/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c +++ b/test/unit/lib/iscsi/iscsi.c/iscsi_ut.c @@ -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 diff --git a/test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c b/test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c index 84310375a..d80df8b03 100644 --- a/test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c +++ b/test/unit/lib/scsi/scsi_bdev.c/scsi_bdev_ut.c @@ -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); }